반응형

사용자에게 상태를 알리거나 동작을 물어보는 용도로 사용되는 팝업 메세지를 구현하는 방법으로

AlertDialog가 있다.

- AlertDialog는 Title, Content, Actions영역으로 구분되며, 세 항목은 필수 항목은 아니다.

- AlertDialog는 showDialog라는 함수를 통하여 화면에 출력된다.

- Dialog를 닫을 때에는 Navigator.pop(context); 를 호출하여 이전 화면이 출력되도록 한다.

- 기본적으로 Dialog의 바깥 화면을 터치하면 Navigator.pop(context); 를 수행한 것처럼 Dialog가 닫힌다.

  이것을 방지하기 위해 showDialog의 barrierDismissible의 속성값을 false로 지정하면,

  Dialog 바깥 화면이 터치되지 않는다.

- Dialog의 모서리는 AlertDialog의 shape 속성에 RoundedRectangleBorder를 추가하면 된다.

 

 

void _showDialog() { 
    showDialog(
      context: context,
      barrierDismissible: false, 
      builder: (BuildContext context) { 
        return AlertDialog(
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(8.0)
          ),
          title: new Text("Alert Dialog title"),
          content: SingleChildScrollView(child:new Text("Alert Dialog body")),
          actions: <Widget>[ 
            new FlatButton(
              child: new Text("Close"),
              onPressed: () {
                Navigator.pop(context);
              },
            ),
          ],
        );
      },
    );
  }

 

반응형

+ Recent posts