Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. @override
  2. Widget build(BuildContext context) {
  3. customers = getAllCustomers();
  4.  
  5. return Scaffold(
  6. appBar: _getAppBar(),
  7. body: customers != null
  8. ? FutureBuilder(
  9. future: getFavouriteCustomers(), // contains IDs of favourite customers
  10. builder: (context, snapshot) {
  11. if (snapshot.connectionState == ConnectionState.done) {
  12. if (snapshot.hasData) {
  13. List<String> favouriteCustomersList = snapshot.data;
  14.  
  15. return ListView.builder(
  16. itemCount: customers?.length ?? 0,
  17. itemBuilder: (BuildContext context, int index) {
  18. customer c = customers?.elementAt(index);
  19.  
  20. if (favouriteCustomersList.contains(c.id)) {
  21. c.isSelected = true;
  22. }
  23.  
  24. return ListTile(
  25. title: Text(c.name),
  26. trailing: Checkbox(
  27. value: c.isFavourite,
  28. onChanged: (newValue) {}),
  29. onTap: () {
  30. if (c.isSelected) {
  31. setState(() {
  32. c.setFavourite(false);
  33. });
  34. } else {
  35. setState(() {
  36. c.setFavourite(true);
  37. }
  38. }
  39. },
  40. );
  41. });
  42. }
  43. } else {
  44. return CircularProgressIndicator();
  45. }
  46. })
  47. : Center(
  48. child: CircularProgressIndicator(),
  49. );
  50. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement