I have create a simple listView like this
ListView DiagnosisListWidget(BuildContext context) {
return ListView.builder(
shrinkWrap: true,
scrollDirection: Axis.horizontal,
itemCount: global_Diagnosis.length,
itemBuilder: (BuildContext context, int index) => Padding(
padding: const EdgeInsets.only(left: 13),
child: Container(
width: 300,
height: 100,
child: GestureDetector(
// onTap: widget.onPressed,
onTap: () {},
child: RichText(
text: new TextSpan(
// Note: Styles for TextSpans must be explicitly defined.
// Child text spans will inherit styles from parent
style: new TextStyle(
fontSize: 14.0,
color: Colors.black,
),
children: <TextSpan>[
new TextSpan(
text: 'Name : ',
style: new TextStyle(
fontSize: 13, fontFamily: 'PoppinsMedium')),
new TextSpan(
text: '${global_Diagnosis[index]['diagName']}',
style: TextStyle(
fontSize: 13,
fontFamily: 'PoppinsRegular',
color: textGreyColor)),
],
),
)),
),
),
);
}
I am just calling this on different pages the issue i am facing is its not updating mean on which page i am adding global_Diagnosis and showing this listView i need to goBack and come again to see my list or need to use setState. I want some simple solution it will automatically change it self without setState
What i try is i create a class like this
var global_Diagnosis = [];
class DiagnosisItemClass extends ChangeNotifier {
DiagnosisItemClass(String name, int id, String comments) {
_name = name;
_comments = comments;
_id = id;
}
String _comments; // to know active index
String _name;
int _id;
void toggleSelected() {
notifyListeners(); // To rebuild the Widget
}
String getName() {
notifyListeners(); // To rebuild the Widget
return _name;
}
String getComments() {
notifyListeners(); // To rebuild the Widget
return _comments;
}
int getID() {
notifyListeners(); // To rebuild the Widget
return _id;
}
}
I am adding in my array like this
global_Diagnosis.add(DiagnosisItemClass(_quickList[index]['diagnosisName'], _quickList[index]['diagnosisId'], _comments.text));
and showing like this
ListView DiagnosisListWidget(BuildContext context) {
return ListView.builder(
shrinkWrap: true,
scrollDirection: Axis.horizontal,
itemCount: global_Diagnosis.length,
itemBuilder: (BuildContext context, int index) => Padding(
padding: const EdgeInsets.only(left: 13),
child: Container(
width: 300,
height: 100,
child: GestureDetector(
// onTap: widget.onPressed,
onTap: () {},
child: RichText(
text: new TextSpan(
// Note: Styles for TextSpans must be explicitly defined.
// Child text spans will inherit styles from parent
style: new TextStyle(
fontSize: 14.0,
color: Colors.black,
),
children: <TextSpan>[
new TextSpan(
text: 'Name : ',
style: new TextStyle(
fontSize: 13,
fontFamily: 'PoppinsMedium')),
new TextSpan(
text: '${global_Diagnosis[index].getName()}',
style: TextStyle(
fontSize: 13,
fontFamily: 'PoppinsRegular', color: textGreyColor)),
],
),
),
),
),
),
);
}
I dont know i am trying on right direction or not but i have read in some answers someone doing something like this but its not working for me.