import 'package:flutter/cupertino.dart';
|
import 'package:flutter/material.dart';
|
|
import '../../common/page_config.dart';
|
import 'card_item.dart';
|
|
class MatCard extends StatefulWidget {
|
final Map<String, dynamic> item;
|
final bool isEdit;
|
|
final VoidCallback? update;
|
final VoidCallback? delete;
|
|
const MatCard({super.key, required this.item, this.update, this.delete,required this.isEdit});
|
|
@override
|
State<MatCard> createState() => _MatCardState();
|
}
|
|
class _MatCardState extends State<MatCard> {
|
Widget BtnSpace({
|
required update,
|
required delete,
|
required isEdit,
|
}) {
|
if (isEdit == true) {
|
return Row(
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
children: [
|
IconButton(
|
onPressed: widget.update,
|
icon: Icon(
|
Icons.create,
|
color: Colors.green,
|
)),
|
IconButton(
|
onPressed: widget.delete,
|
icon: Icon(
|
Icons.delete_sweep,
|
color: Colors.red,
|
)),
|
],
|
);
|
} else {
|
return SizedBox.shrink();
|
}
|
|
}
|
@override
|
Widget build(BuildContext context) {
|
var showList = [];
|
pageConfig.forEach((element) {
|
widget.item.forEach((key, value) {
|
if (element['title'] == key) {
|
element['value'] = value;
|
}
|
});
|
if (element['isShow'] == true) {
|
showList.add(element);
|
}
|
});
|
|
return Container(
|
margin: EdgeInsets.only(left: 0, top: 8, right: 0, bottom: 8),
|
padding: EdgeInsets.all(8),
|
decoration: BoxDecoration(
|
color: Colors.white, borderRadius: BorderRadius.circular(10)),
|
constraints: BoxConstraints(),
|
child: Row(
|
children: [
|
Expanded(
|
child: Container(
|
child: Column(
|
children: List.generate(showList.length, (index) {
|
var title = showList[index]['title'];
|
var propName = showList[index]['propName'];
|
var value = widget.item[propName];
|
var isShow = showList[index]['isShow'];
|
if (isShow == false) {
|
return SizedBox.shrink();
|
} else {
|
return CardItem(title: title, value: value);
|
}
|
}),
|
))),
|
Container(
|
child: BtnSpace(isEdit: widget.isEdit, update: widget.update,delete: widget.delete),
|
)
|
],
|
));
|
}
|
}
|