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 [showGeneralDialog].
8
9void main() => runApp(const GeneralDialogApp());
10
11class GeneralDialogApp extends StatelessWidget {
12 const GeneralDialogApp({super.key});
13
14 @override
15 Widget build(BuildContext context) {
16 return const MaterialApp(restorationScopeId: 'app', home: GeneralDialogExample());
17 }
18}
19
20class GeneralDialogExample extends StatelessWidget {
21 const GeneralDialogExample({super.key});
22
23 @override
24 Widget build(BuildContext context) {
25 return Scaffold(
26 body: Center(
27 child: OutlinedButton(
28 onPressed: () {
29 /// This shows an alert dialog.
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 RawDialogRoute<void>(
41 pageBuilder: (
42 BuildContext context,
43 Animation<double> animation,
44 Animation<double> secondaryAnimation,
45 ) {
46 return const AlertDialog(title: Text('Alert!'));
47 },
48 );
49 }
50}
51

Provided by KDAB

Privacy Policy
Learn more about Flutter for embedded and desktop on industrialflutter.com