I have of many checkboxes as You can see the image uploaded, please see the image first.
Now the problem is that you can see the 3 cards views Conditions, Allergies and Past Surgeries. and all of these cards contains checkboxes and now what happens is that when I check or uncheck any box the UI of the CheckBox doesn't update to tick or untick and I have checkboxes outside the build method.
Can anyone let me know that what am I doing wrong and I will share the checkboxes codes also?
EDIT
CREATING CHECK BOXES DYNAMICALLY
List<Widget> _dynamicListWidget(List<dynamic> list) {
List<Widget> widgetList = List<Widget>();
for (var i = 0; i < list.length; i++) {
Condition condition = list[i];
widgetList.add(
Container(
width: _containerWidth,
//padding: EdgeInsets.only(top: 2, bottom: 2),
child: Row(
children: <Widget>[
Expanded(
child: Container(
margin: EdgeInsets.only(left: 10),
child: Text(condition.name, style: _textStyle),
)),
//Expanded(child: Container()),
Checkbox(
value: condition.selected,
onChanged: (bool value) {
print("$value value");
setState(() {
condition.selected = value;
});
addRemoveFavHealth(value, condition.id);
},
),
],
),
),
);
}
return widgetList;
}
CREATING A CARD VIEW
Widget mainbody(String name, List<dynamic> dynamicList) {
final screenWidth = MediaQuery.of(context).size.width;
final screenheight = MediaQuery.of(context).size.height;
print("$screenWidth width of device");
List<Condition> list = List();
return Container(
width: screenWidth * 0.49,
child: Card(
color: Colors.white,
child: Column(
children: <Widget>[
Container(
//width: 200,
padding: EdgeInsets.symmetric(vertical: 8, horizontal: 8),
decoration: BoxDecoration(
color: Colors.black12,
),
child: Row(
children: <Widget>[
ClipOval(
child: Material(
color: Colors.white,
child: SizedBox(
width: 40,
height: 40,
child:
/*Image.asset(
'assets/icons/doc_icon.png'),*/
Icon(
Icons.playlist_add_check,
color: AppTheme.primaryColor,
),
),
),
),
Flexible(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
_localization.localeString(name),
style: TextStyle(color: AppTheme.primaryColor),
),
],
),
),
),
],
),
),
Container(
child: Column(
children: _dynamicListWidget(list),
),
),
],
),
),
);
}
BUILD METHOD
@override
Widget build(BuildContext context) {
_localization = AppTranslations.of(context);
return Expanded(
child: SingleChildScrollView(
child: Column(
children: _mainList,
),
)
);
}
In the build method, _mainList is the list of the MAINBODY METHOD.
Aucun commentaire:
Enregistrer un commentaire