0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Flutterで、Drawerから子画面を開いた際にDrawerを閉じる

Posted at

問題点

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が閉じた状態になりました!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?