@@ -11,41 +11,63 @@ void main() => runApp(const MyApp());
1111class MyApp extends StatelessWidget {
1212 const MyApp ({Key ? key}) : super (key: key);
1313
14- static const String _title = 'Flutter Code Sample' ;
15-
1614 @override
1715 Widget build (BuildContext context) {
1816 return const MaterialApp (
19- restorationScopeId: 'app' ,
20- title: _title,
21- home: MyStatelessWidget (),
17+ home: DialogExample (),
2218 );
2319 }
2420}
2521
26- class MyStatelessWidget extends StatelessWidget {
27- const MyStatelessWidget ({Key ? key}) : super (key: key);
22+ class DialogExample extends StatelessWidget {
23+ const DialogExample ({Key ? key}) : super (key: key);
2824
2925 @override
3026 Widget build (BuildContext context) {
3127 return Scaffold (
28+ appBar: AppBar (title: const Text ('showDialog Sample' )),
3229 body: Center (
3330 child: OutlinedButton (
34- onPressed: () {
35- Navigator .of (context).restorablePush (_dialogBuilder);
36- },
31+ onPressed: () => _dialogBuilder (context),
3732 child: const Text ('Open Dialog' ),
3833 ),
3934 ),
4035 );
4136 }
4237
43- static Route <Object ?> _dialogBuilder (
44- BuildContext context, Object ? arguments) {
45- return DialogRoute <void >(
38+ Future <void > _dialogBuilder (BuildContext context) {
39+ return showDialog <void >(
4640 context: context,
47- builder: (BuildContext context) =>
48- const AlertDialog (title: Text ('Material Alert!' )),
41+ builder: (BuildContext context) {
42+ return AlertDialog (
43+ title: const Text ('Basic dialog title' ),
44+ content: const Text (
45+ 'A dialog is a type of modal window that\n '
46+ 'appears in front of app content to\n '
47+ 'provide critical information, or prompt\n '
48+ 'for a decision to be made.' ),
49+ actions: < Widget > [
50+ TextButton (
51+ style: TextButton .styleFrom (
52+ textStyle: Theme .of (context).textTheme.labelLarge,
53+ ),
54+ child: const Text ('Disable' ),
55+ onPressed: () {
56+ Navigator .of (context).pop ();
57+ },
58+ ),
59+ TextButton (
60+ style: TextButton .styleFrom (
61+ textStyle: Theme .of (context).textTheme.labelLarge,
62+ ),
63+ child: const Text ('Enable' ),
64+ onPressed: () {
65+ Navigator .of (context).pop ();
66+ },
67+ ),
68+ ],
69+ );
70+ },
4971 );
5072 }
5173}
0 commit comments