1// Copyright 2014 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'package:flutter/material.dart';
6
7/// Flutter code sample for [showDialog].
8
9void main() => runApp(const ShowDialogExampleApp());
10
11class ShowDialogExampleApp extends StatelessWidget {
12 const ShowDialogExampleApp({super.key});
13
14 @override
15 Widget build(BuildContext context) {
16 return const MaterialApp(restorationScopeId: 'app', home: DialogExample());
17 }
18}
19
20class DialogExample extends StatelessWidget {
21 const DialogExample({super.key});
22
23 @override
24 Widget build(BuildContext context) {
25 return Scaffold(
26 appBar: AppBar(title: const Text('AlertDialog Sample')),
27 body: Center(
28 child: OutlinedButton(
29 onPressed: () {
30 Navigator.of(context).restorablePush(_dialogBuilder);
31 },
32 child: const Text('Open Dialog'),
33 ),
34 ),
35 );
36 }
37
38 @pragma('vm:entry-point')
39 static Route<Object?> _dialogBuilder(BuildContext context, Object? arguments) {
40 return DialogRoute<void>(
41 context: context,
42 builder: (BuildContext context) {
43 return AlertDialog(
44 title: const Text('Basic dialog title'),
45 content: const Text(
46 'A dialog is a type of modal window that\n'
47 'appears in front of app content to\n'
48 'provide critical information, or prompt\n'
49 'for a decision to be made.',
50 ),
51 actions: <Widget>[
52 TextButton(
53 style: TextButton.styleFrom(textStyle: Theme.of(context).textTheme.labelLarge),
54 child: const Text('Disable'),
55 onPressed: () {
56 Navigator.of(context).pop();
57 },
58 ),
59 TextButton(
60 style: TextButton.styleFrom(textStyle: Theme.of(context).textTheme.labelLarge),
61 child: const Text('Enable'),
62 onPressed: () {
63 Navigator.of(context).pop();
64 },
65 ),
66 ],
67 );
68 },
69 );
70 }
71}
72