1
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】画面のスタート時にダイアログを表示する方法

Posted at

はじめに

Flutterで画面遷移した際や、アプリを起動した際など、画面の最初にダイアログを表示したいと思い調べてみたんですが、日本語の記事を見つけられなかったので記事にします

ステップ1

ダイアログを呼ぶ関数を用意する

dialog.dart
Future<void> _showStartDialog() async {
    return showDialog<void>(
      context: context,
      builder: (BuildContext context) {
        return AlertDialog(
          title : Text('タイトルテキスト'),
          content: Text("コンテントテキスト"),
          actions: <Widget>[
            TextButton(
              child: Text('OK'),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
          ],
        );
      },
    );
  }

ファイルのinitStateで呼び出す

dialog.dart
void initState() {
    super.initState();
    WidgetsBinding.instance!.addPostFrameCallback(
            (_) => _showStartDialog()//
    );
  }

この書き方についてはこちらの記事に書いてあります。

これで以上です!おつかれさまです!

1
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
1
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?