Flutter

[Flutter] 경고창 띄우고 닫기

유호야 2022. 12. 2. 23:23
반응형

AlertDialog

경고창을 띄우는 방식이다.

Navigator.pop(context) 을 통해서 창을 닫는 기능까지 구현 가능하다.

                    TextButton(
                      style: ButtonStyle(
                          shadowColor: MaterialStateProperty.all(Colors.red),
                          backgroundColor: MaterialStateProperty.all(
                            Theme.of(context).cardColor,
                          )),
                      onPressed: () {
                        showDialog(
                            context: context,
                            builder: (context) => AlertDialog(
                                  title: const Text('Are you nuts?'),
                                  // content: Text('Of course not!'),
                                  actions: [
                                    TextButton(
                                      onPressed: () {
                                        Navigator.pop(context);
                                      },
                                      child: const Text('YES'),
                                    ),
                                    TextButton(
                                      onPressed: () {
                                        Navigator.pop(context);
                                      },
                                      child: const Text('NO'),
                                    ),
                                  ],
                                ));
                      },

 

 

 

AlertDialog class - material library - Dart API

A Material Design alert dialog. An alert dialog (also known as a basic dialog) informs the user about situations that require acknowledgement. An alert dialog has an optional title and an optional list of actions. The title is displayed above the content a

api.flutter.dev

 

반응형