0
votes

now i made the code like this

 FutureBuilder(
                future: getData2(),
                builder: (context, snapshot) {
                  if (snapshot.hasData) {
                    List data = snapshot.data;
                    return ListView.builder(
                      shrinkWrap: true,
                      itemCount: data.length,
                      itemBuilder: (context, index) {
                        final item = data[index];
                        return Dismissible(
                          key: Key(item['loc3']),
                          onDismissed: (direction) {
                            setState(() async {
                              await openData2().then((value) {
                                value.delete(
                                  'test2',
                                  where: 'loc3 = ?',
                                  whereArgs: ['loc3'],
                                );
                              });
                            });
                          },
                          child: ListTile(
                            title: Text(item['loc3']),
                          ),
                        );
                      },
                    );

but when i dismiss one item there's some note in console 'Another exception was thrown: setState() callback argument returned a Future.' in setState i don't return any variable
why they say like this?

and when i first delete one item there is more detail error

The following assertion was thrown while notifying listeners for AnimationController:
I/flutter ( 6018): setState() callback argument returned a Future.
I/flutter ( 6018): The setState() method on PositionedTilesState#6d110 was called with a closure or method that
I/flutter ( 6018): returned a Future. Maybe it is marked as "async".
I/flutter ( 6018): Instead of performing asynchronous work inside a call to setState(), first execute the work (without
I/flutter ( 6018): updating the widget state), and then synchronously update the state inside a call to setState().
I/flutter ( 6018): When the exception was thrown, this was the stack:

1

1 Answers

0
votes

I think the 1 problem is that you have an async function inside setState. Change it to this:

...
                              onDismissed: (direction) async {
                              await openData2().then((value) {
                                    value.delete(
                                      'test2',
                                      where: 'loc3 = ?',
                                      whereArgs: ['loc3'],
                                    );
                                  });
                              setState(() {});
                              },
'''

or this (more readable):

...
                              onDismissed: (direction) {

                           Future<void> delete() async {
                               await openData2().then((value) {
                                    value.delete(
                                      'test2',
                                      where: 'loc3 = ?',
                                      whereArgs: ['loc3'],
                                    );
                                  });
                                 }

                              setState(() {
                                   delete();
                                     });
                                    },
'''

The point is, you can't have async operations performed inside setState.