問題点
FlutterでDrawerから子画面を開いた際に、子画面を閉じた時にDrawerが開きっぱなしになってしまう。
解決方法
子画面の遷移前に、
Navigator.of(context).pop();
を入れる。
実際にやってみる
drawer: Drawer(
child: Align(
alignment: Alignment.topLeft,
child: ListView(
children: [
SizedBox(
height: 65,
child: DrawerHeader(
child: userState.nickName != null
? Text(
userState.nickName! + ' さん',
style: const TextStyle(
fontSize: 24, color: Colors.white),
)
: const Text('メニュー'),
decoration: const BoxDecoration(
color: AppColors.mainBackColorMaterial)),
),
ListTile(
title: const Text('共有'),
trailing: const Icon(Icons.people_alt_outlined),
onTap: () {
///★ここで、遷移前に閉じておく!
Navigator.of(context).pop();
///リストID入力画面に遷移(InputDialogは独自Widget)
showDialog(
context: context,
builder: (BuildContext context) {
return InputDialog(
title: '共有する',
onPressed: () {
},
description: ('共有IDが記載されたメールが送信されます。'),
);
},
).then((value) => null);
},
),
],
),
))
子画面で「キャンセル」を押して、元の画面に戻ると、Drawerが閉じた状態になりました!