22
11

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 5 years have passed since last update.

FlutterでScaffoldをModal表示する

Posted at

こんな風にScaffoldをModalで表示する方法を紹介します。

Navigator.push するときに渡すMaterialPageRoutefullscreenDialog をtrueにしておけば、モーダル表示されます。

コード例はこんなかんじ。Screen1からScreen2をモーダル表示します。

class Screen1 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("Screen1")),
      body: Center(
        child: RaisedButton(
          onPressed: () {
            Navigator.push(
                context,
                MaterialPageRoute(
                    builder: (BuildContext context) {
                      return Screen2();
                    },
                    fullscreenDialog: true));
          },
          child: Text("show modal screen"),
        ),
      ),
    );
  }
}

class Screen2 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("Screen2")),
      body: Center(
        child: Text("This is modal!!"),
      ),
    );
  }
}

参考
https://kwmt27.net/2018/07/28/flutter-navigator-modal/

22
11
1

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
22
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?