【发布时间】:2021-08-27 07:32:13
【问题描述】:
我想同时使用这样的滑动从 listview 和 db 中删除一个条目:
onPressed: () {
// Delete the item from DB
setState(() {
data.indexOf(data[index]);
data.removeAt(index);
});
Navigator.of(context).pop();
},
该方法似乎不起作用,我也需要有关如何在没有用户重新打开页面的情况下触发此页面上的更新的帮助。
return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (context, index) {
List<Ia> data = snapshot.data;
print(data);
return Dismissible(
background: slideRightBackground(),
secondaryBackground: slideLeftBackground(),
key: Key(data[index].toString()),
// ignore: missing_return
confirmDismiss: (direction) async {
if (direction == DismissDirection.endToStart) {
final bool res = await showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
content: Text(
"Are you sure you want to delete ` ${data[index]}?"),`
actions: <Widget>[
// ignore: deprecated_member_use
FlatButton(
child: Text(
"Cancel",
style:
TextStyle(color: Colors.black),
),
onPressed: () {
Navigator.of(context).pop();
},
),
FlatButton(
child: Text(
"Delete",
style: TextStyle(color: Colors.red),
),
onPressed: () {
// Delete the item from DB
setState(() {
data.indexOf(data[index]);
data.removeAt(index);
});
Navigator.of(context).pop();
},
),
],
);
});
return res;
} else {
// Navigate to edit page;
}
},
child: Card(
child: ListTile(
title: Text(data[index].name,
style: TextStyle(fontSize: 16)),
subtitle: Row(
children: [
Text(
"Status",
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold),
),
SizedBox(
width: 5,
),
Text(
data[index].state,
style: TextStyle(
color: Colors.lightBlue,
fontSize: 12,
),
),
],
),
),
),
);
});
/////////////////////////////////////// ///////////////////////////////////////// ///////////////////////////////////////// ///////////////////////////////////////// ///////////////////////////////////////// ///////////////////////////////////////// ///////////////////////////////////////// ///////////////////////////////////////// ///////////////////////////////////////// ///////////////////////////////////////// ///////////////////////////////////////// ///////////////////////////////////////// ///////////////////////////////////////// ///////////////////////////////////////// //////////////
【问题讨论】:
标签: flutter dart flutter-layout flutter-dependencies flutter-web