ShowDialog(팝업 메세지)

이원석·2023년 12월 6일
0

Flutter

목록 보기
37/46

ShowDialog

ShowDialogAlertDialog를 활용하여 팝업 메세지를 구현할 수 있다.

ShowDialog

ShowDialog는 일반적으로 Dialog를 빌드하는데 사용
필수 속성으로 context와 builder를 같는다.
barrierDismissible은 팝업메세지가 띄워졌을 때 뒷배경의 touchEvent가능 여부에 대한 값이다. fasle로 넣어주면 뒷배경의 touchEvent를 막는다.

AlertDialog

AlertDialog는 사용자에게 승인이 필요한 상황을 알려준다.

  • title : 제목
  • center : 내용
  • action : 버튼

Example

onTap: () {
                          showDialog(
                              context: context,
                              builder: (ctx) {
                                return AlertDialog(
                                  title: const Text('삭제'),
                                  content: const Text('을/를 빼겠습니까?'),
                                  actions: <Widget>[
                                    ElevatedButton(
                                      onPressed: () {
                                        return Navigator.of(context).pop(false);
                                      },
                                      child: const Text('취소'),
                                    ),
                                    ElevatedButton(
                                      onPressed: () {
                                        return Navigator.of(context).pop(true);
                                      },
                                      child: const Text('삭제'),
                                    ),
                                  ],
                                );
                              });
                        },

0개의 댓글