When I open this Dialog and after press one of the button, it can't auto close. Is my navigator wrong? ? How to fix this problem ? Please help me, thanks.
I can’t understand why this pop-up window still stays on the page and my page jumped one page forward, shouldn’t it be popped by the Navigator?
this is my code first widget is the Delete function&UI, second widget is show main List widget, it use ListTile.
Widget _checkDelete({String title, String detail, String uid}) {
ThemeData themeData = Theme.of(context);
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(8.0))),
child: Container(
padding: EdgeInsets.all(16),
decoration: new BoxDecoration(
color: themeData.backgroundColor,
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(8),
boxShadow: [
BoxShadow(
color: Colors.black26,
blurRadius: 10.0,
offset: const Offset(0.0, 10.0),
),
],
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text("$title",
style: AppTheme.getTextStyle(
themeData.textTheme.headline6,
fontWeight: FontWeight.w600,
)),
Text("$detail",
style: AppTheme.getTextStyle(
themeData.textTheme.subtitle1,
fontWeight: FontWeight.w400,
)),
Container(
alignment: AlignmentDirectional.centerEnd,
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
FlatButton(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
padding: EdgeInsets.all(0),
splashColor: themeData.colorScheme.primary.withAlpha(150),
onPressed: () {
Navigator.pop(context);
},
child: Text(
"取消",
style: AppTheme.getTextStyle(
themeData.textTheme.bodyText2,
fontWeight: FontWeight.w500,
color: themeData.colorScheme.primary),
)),
FlatButton(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
padding: EdgeInsets.all(0),
splashColor: themeData.colorScheme.primary.withAlpha(150),
onPressed: () async {
final db = Firestore.instance;
db
.collection('users')
.document(uid)
.updateData({'staff': false}).then((value) =>
showDialog(
context: context,
builder: (BuildContext context) =>
_simpleDialog(
title: '刪除成功',
detail: '已經成功移除客服')));
Navigator.pop(context);
initList();
},
child: Text(
"刪除",
style: AppTheme.getTextStyle(
themeData.textTheme.bodyText2,
fontWeight: FontWeight.w500,
color: Colors.red),
)),
],
),
),
],
),
),
);
}
ThemeData themeData;
ListView _staffList = ListView(
padding: EdgeInsets.all(16),
children: <Widget>[],
);
Future<Null> _onRefresh() async {
await Future.delayed(Duration(milliseconds: 2000));
initList();
return null;
}
initList() async {
final db = Firestore.instance;
db
.collection('users')
.where('staff', isEqualTo: true)
.getDocuments()
.then((datas) {
setState(() {
_staffList = ListView(
padding: EdgeInsets.all(16),
children: <Widget>[
for (var data in datas.documents)
ListTile(
leading: CircleAvatar(
child: Text(data.data['name'][0]),
),
trailing: IconButton(
icon: Icon(Icons.delete),
onPressed: () async{
showDialog(
context: context,
builder: (BuildContext context) => _checkDelete(
title: '確定要移除 ${data.data['name']} 的權限嗎?',
detail: '這個帳號將恢復為一般帳號,不會被刪除。',
uid: data.documentID));
}), //this showDialog can't close when I pressed button
subtitle: Text(data.documentID),
title: Text(data.data['name']),
),
],
);
});
});
}
@override
initState() {
super.initState();
initList();
}