Condition must have static type of bool
11,774
Use in initState()
like
bool alreadySaved = false;
@override
void initState() {
super.initState();
String pair = "pair_value";
DBHelper.getAllEmployees().then((value) {
setState(() {
alreadySaved = value.contains(pair);
});
});
}
Author by
Adrita Rahman
Updated on June 30, 2022Comments
-
Adrita Rahman almost 2 years
I am not able to use future bool here.. is there any way i can use future bool in this type of conditions.. or is there any better way to do this?
Widget _buildRow(String pair) { final Future<bool> alreadySaved = DBHelper.getAllEmployees().then((value) => value.contains(pair)); print("Already saved $alreadySaved"); print(pair); return FutureBuilder( future: DBHelper.getAllEmployees(), builder: (context, AsyncSnapshot<List<FavrtTableModel>> snapshot) => snapshot.connectionState == ConnectionState.waiting ? Center( child: Icon(Icons.more_horiz), ):IconButton( icon: new Icon( alreadySaved ? Icons.favorite : Icons.favorite_border, color:alreadySaved? Colors.red : Colors.white, ),onPressed: (){ setState(() { if (alreadySaved) { _saved.remove(pair); _deleteEmployee(pair); } else { _saved.add(pair); _insert(pair); } }); }, ), ); }
-
Adrita Rahman over 3 yearsi thought of that.. but the problem is in the pair value.. it cannot be shifted to initstate(),.. actually the pair value comes from a future builder in another widget,.
-
Jitesh Mohite over 3 yearsThat's ok but you can move this logic to another widget class? and pass pair value to that widget. or maybe you can create stateful widget for that and use initState() like my answer
-
Adrita Rahman over 3 yearssorry.. i forgot..Thank you!
-
funder7 over 3 yearsI was thinking about all except this...thanks!