当使用Dismissible小部件时,有没有一种方法可以在对话框中显示正在被驳回的项目



我正在创建一个应用程序,它从存储库中提取人员,然后在屏幕上显示他们。用户应该能够通过向右滑动将此人从存储库中删除。当用户向右滑动时,会触发confirmDismiss:属性,弹出对话框询问用户是否确定。

对话框中的content:有可能是那个人名吗。因此,如果有人想从名单中删除尼古拉斯·凯奇,就会说";你确定要删除Nicolas Cage吗&";。

Person类就是这样实现的:

class Person {
int _id;
String _fullName;
String _email;
String _mobile;
String _other;
Person(int id, String fullName, String email, String mobile, String other) {
this._id = id;
this._fullName = fullName;
this._email = email;
this._mobile = mobile;
this._other = other;
}
}

这就是可撤销确认Dissmis的实现方式:

confirmDismiss: (direction) async {
bool response = await showDialog<bool>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
content: const Text('Are you sure you want to delete '),
actions: <Widget>[
FlatButton(
child: const Text('Yes'),
onPressed: () => Navigator.pop(context, true),
),
FlatButton(
child: const Text('No'),
onPressed: () => Navigator.pop(context, false),
),
],
);
},
);
},

在AlertDialog内容中,我希望它说";你确定要删除Nicolas Cage吗"如果我们假设用户在Nicolas Cage列表磁贴上向右滑动我试过的这种方法行不通。它说这个常量表达式的求值抛出一个异常,无效的常量值。

只需将people[index].namecontent: Text('Are you sure you want to delete ')附加为content: Text('Are you sure you want to delete ' + people[index].fullName)

代码:

confirmDismiss: (direction) async {
bool response = await showDialog<bool>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
content: Text('Are you sure you want to delete the user: ${people[index].fullName}'),
actions: <Widget>[
FlatButton(
child: const Text('Yes'),
onPressed: () => Navigator.pop(context, true),
),
FlatButton(
child: const Text('No'),
onPressed: () => Navigator.pop(context, false),
),
],
);
},
);
},

最新更新