Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @override
- Widget build(BuildContext context) {
- customers = getAllCustomers();
- return Scaffold(
- appBar: _getAppBar(),
- body: customers != null
- ? FutureBuilder(
- future: getFavouriteCustomers(), // contains IDs of favourite customers
- builder: (context, snapshot) {
- if (snapshot.connectionState == ConnectionState.done) {
- if (snapshot.hasData) {
- List<String> favouriteCustomersList = snapshot.data;
- return ListView.builder(
- itemCount: customers?.length ?? 0,
- itemBuilder: (BuildContext context, int index) {
- customer c = customers?.elementAt(index);
- if (favouriteCustomersList.contains(c.id)) {
- c.isSelected = true;
- }
- return ListTile(
- title: Text(c.name),
- trailing: Checkbox(
- value: c.isFavourite,
- onChanged: (newValue) {}),
- onTap: () {
- if (c.isSelected) {
- setState(() {
- c.setFavourite(false);
- });
- } else {
- setState(() {
- c.setFavourite(true);
- }
- }
- },
- );
- });
- }
- } else {
- return CircularProgressIndicator();
- }
- })
- : Center(
- child: CircularProgressIndicator(),
- );
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement