반응형
1. 별도 메소드 작성
Future<void> _dialogBuilder(BuildContext context) {
return showDialog<void>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Basic dialog title'),
content: const Text(
'A dialog is a type of modal window that\n'
'appears in front of app content to\n'
'provide critical information, or prompt\n'
'for a decision to be made.',
),
actions: <Widget>[
TextButton(
style: TextButton.styleFrom(
textStyle: Theme.of(context).textTheme.labelLarge,
),
child: const Text('Disable'),
onPressed: () {
Navigator.of(context).pop();
},
),
TextButton(
style: TextButton.styleFrom(
textStyle: Theme.of(context).textTheme.labelLarge,
),
child: const Text('Enable'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
2. 기존 레이아웃에서 Context 전달
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.blue,
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () => _dialogBuilder(context),
tooltip: 'Increment',
backgroundColor: Colors.white,
child: const Icon(Icons.add,color: Colors.black,),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
해당 버튼 클릭했을때 팝업이 나오게 할 수있다.
반응형
'[Mobile] > [Flutter]' 카테고리의 다른 글
[Flutter] SharedPreferences 사용하여 입/출력 정리 (0) | 2023.07.25 |
---|---|
[Flutter] shared_preferences 사용 (0) | 2023.07.23 |
[Flutter] 착한 사람들이 많은 플러터 (0) | 2023.07.20 |
[Flutter] Splash Page 만들기 (1) | 2023.07.19 |
[Flutter] Dart Sdk 버전업 (1) | 2023.07.18 |