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 | |
5 | import 'package:flutter/cupertino.dart'; |
6 | |
7 | /// Flutter code sample for [showCupertinoModalPopup]. |
8 | |
9 | void main() => runApp(const ModalPopupApp()); |
10 | |
11 | class ModalPopupApp extends StatelessWidget { |
12 | const ModalPopupApp({super.key}); |
13 | |
14 | @override |
15 | Widget build(BuildContext context) { |
16 | return const CupertinoApp( |
17 | theme: CupertinoThemeData(brightness: Brightness.light), |
18 | restorationScopeId: 'app', |
19 | home: ModalPopupExample(), |
20 | ); |
21 | } |
22 | } |
23 | |
24 | class ModalPopupExample extends StatelessWidget { |
25 | const ModalPopupExample({super.key}); |
26 | |
27 | @override |
28 | Widget build(BuildContext context) { |
29 | return CupertinoPageScaffold( |
30 | navigationBar: const CupertinoNavigationBar(middle: Text('Home')), |
31 | child: Center( |
32 | child: CupertinoButton( |
33 | onPressed: () { |
34 | Navigator.of(context).restorablePush(_modalBuilder); |
35 | }, |
36 | child: const Text('Open Modal'), |
37 | ), |
38 | ), |
39 | ); |
40 | } |
41 | |
42 | @pragma('vm:entry-point') |
43 | static Route<void> _modalBuilder(BuildContext context, Object? arguments) { |
44 | return CupertinoModalPopupRoute<void>( |
45 | builder: (BuildContext context) { |
46 | return CupertinoActionSheet( |
47 | title: const Text('Title'), |
48 | message: const Text('Message'), |
49 | actions: <CupertinoActionSheetAction>[ |
50 | CupertinoActionSheetAction( |
51 | child: const Text('Action One'), |
52 | onPressed: () { |
53 | Navigator.pop(context); |
54 | }, |
55 | ), |
56 | CupertinoActionSheetAction( |
57 | child: const Text('Action Two'), |
58 | onPressed: () { |
59 | Navigator.pop(context); |
60 | }, |
61 | ), |
62 | ], |
63 | ); |
64 | }, |
65 | ); |
66 | } |
67 | } |
68 |