Home > Blockchain >  Flutter: How can update the list.generate on delete item?
Flutter: How can update the list.generate on delete item?

Time:02-11

I want to update the page after deleting a tile. setState is not working... Can u help me? I can delete it from firebase but not update de view

 Widget build(BuildContext context) {
    final UserProvider userProvider = Provider.of<UserProvider>(context);
    return Scaffold(
...
 children: List.generate(
                  userProvider.getUser.player.length,
                  (index) => SizedBox(
                      child: ListTile(
                    contentPadding: const EdgeInsets.only(
                      right: 5,
                      left: 15,
                      top: 0,
                    ),
                    title: AutoSizeText(
                      userProvider.getUser.bands[index].nameP,
                      style: const TextStyle(letterSpacing: 2.0),
                      maxLines: 1,
                    ),
                    subtitle: Text(userProvider.getUser.bands[index].rol),
                    trailing: IconButton(
                      icon: const Icon(CupertinoIcons.trash),
                      onPressed: () {
                        setState(() {
                          deletePlayer(index, userProvider.getUser.uid);
                          
                        });

CodePudding user response:

Don't do setState. Instead add notifyListeners(); on deletePlayer

deletePlayer(int index, String uid){
   //code//
   notifyListeners();
}

CodePudding user response:

onPressed: () async{
 await deletePlayer(index, userProvider.getUser.uid);
 setState(() {});
}

and use notifyListener() in provider

  • Related