GridDataW function
Widget
GridDataW(
- dynamic Item,
- Map<String, dynamic> map, {
- dynamic show = false,
})
Implementation
Widget GridDataW(Item, Map<String, dynamic> map,{show=false}) {
List<Map<String, dynamic>> listMap = [];
printO(
"Contains ${Item["key"]} ${map.containsKey(Item["key"])} ${map[Item["key"]]}");
StreamController stream = StreamController.broadcast();
List<List<Widget>> listparent = [];
if (map.containsKey(Item["key"]))
//int i=0;
for (int i = 0; i < (map[Item["key"]] as List).length; i++) {
Map<String, dynamic> val = (map[Item["key"]] as List)[i];
List<Widget> list = Item['components']!
.map<Widget>((e) => FormWedgit(e, val, 2,show: show)
)
.toList();
listMap.add(val);
listparent.add(list);
}
else {
listMap.add(new Map<String, dynamic>());
List<Widget> list = Item['components']!
.map<Widget>((e) => Padding(
padding: const EdgeInsets.only(bottom: 8, top: 8),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [FormWedgit(e, listMap.first, 1,show: show)])))
.toList();
// list.insert(0, IconButton(onPressed: (){}, icon: Icon(Icons.remove_circle)),);
listparent.add(list);
}
Future.delayed(Duration(milliseconds: 500), () {
stream.add(listparent);
});
return FormBuilderField(
name: Item['key'],
// Item['key'],
enabled: !show,
onSaved: (value) {
map[Item['key']] = listMap;
},
builder: (FormFieldState<dynamic> field) {
field.value;
return StreamBuilder(
stream: stream.stream,
builder: (context, snapshot) {
return Column(
mainAxisSize: MainAxisSize.min,
// mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if(Item['hideLabel'] == null || !Item['hideLabel'])
Container(
padding: const EdgeInsets.only(bottom: 5.0,right: 8.0,left: 8.0,top: 5.0),
child: Text(
"${Item['hideLabel'] != null && Item['hideLabel'] ? '' : Item['label']}",style: TextStyle(
fontFamily: 'Tajawal',
fontSize: 14,
//color: const Color(0xff42487e),
height: 1
),),
),
// for (List<Widget> list in snapshot)
if (snapshot.hasData && snapshot.data != null)
for (List<Widget> list
in (snapshot.data as List<List<Widget>>))
Container(
margin: EdgeInsets.only(top: 5.0,right: 5,left: 5,bottom: 10),
padding: EdgeInsets.only(top: 10.0,bottom: 10),
decoration: BoxDecoration(
border:
Border.all(color: ThemeApp!.borderColor, width: 1)),
child: Wrap(
spacing: 5.0,
children: list,
crossAxisAlignment: WrapCrossAlignment.start,
direction: Axis.horizontal,
// verticalDirection: VerticalDirection.down,
alignment: WrapAlignment.start,
runAlignment: WrapAlignment.start,
runSpacing: 5.0,
),
),
// settingRes.formTypeShow.value?SizedBox():
Item['disableAddingRemovingRows'] != true
? Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CupertinoButton(
color: ThemeApp!.primaryColor,
padding: EdgeInsets.only(left: 20,right: 20),
onPressed: () {
listMap.add(new Map<String, dynamic>());
// map[Item['key']]=listMap;
listparent.add(Item['components']!
.map<Widget>((e) => Padding(
padding: const EdgeInsets.only(
bottom: 8, top: 8),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
FormWedgit(e, listMap.last, 1,
row: listparent.length)
])))
.toList());
stream.add(listparent);
},
child: Text("${Item['addAnother']}",style: ThemeApp?.buttonTextStyle,),
),
SizedBox(
width: 10,
),
Item['disableAddingRemovingRows'] != true &&
listparent.length > 1
? CupertinoButton(
padding: EdgeInsets.only(left: 20,right: 20),
color: Colors.redAccent,
onPressed: () {
listMap
.removeLast(); //.add(new Map<String,dynamic>());
listparent.removeLast();
stream.add(listparent);
},
child: Text("delete",style: ThemeApp?.buttonTextStyle,),
// style: ButtonStyle(
// backgroundColor:
// MaterialStateProperty.all(
// Colors.redAccent)),
)
: SizedBox(),
],
),
)
: SizedBox()
]);
});
});
}