I’m using ListView builder that fetches the data from the database and shows it in the list.
Future<dynamic> data = Database.getItems();
child: FutureBuilder(
future: data,
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.data == null) {
return Center(
child: LoadingAnimationWidget.staggeredDotsWave(
color: Colors.blueAccent, size: 50));
} else {
return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (BuildContext context, int index) {
print(snapshot.data[index]);
return ItemWidget(
onEditTap: () {
setState(() {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ItemEditPage(
user: user,
)),
);
data = Database.getItems();
});
},
onDeleteTap: () async {
await Database.delete(snapshot.data[index]["_id"]);
setState(() {
data = Database.getItems();
});
},
},
);
Is there any chance when I press the delete button for an item, it waits for the item (show any loading text or anything) and then refreshes the listview?
onDeleteTap: () async {
await Database.delete(snapshot.data[index]["_id"]);
// ANY KIND OF LOADING TEXT HERE, A PAUSE THEN CALL setState
setState(() {
data = Database.getItems();
});
},
2
Answers
you can use this trick: by pop up a loading dialog
and use it:
First define new variable in your main class like this:
then add this variable in your ItemWidget’s
onDeleteTap
like this:then change your list view to this:
this will show a loading on specific item that you click.