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( |
31 | middle: Text('Home'), |
32 | ), |
33 | child: Center( |
34 | child: CupertinoButton( |
35 | onPressed: () { |
36 | Navigator.of(context).restorablePush(_modalBuilder); |
37 | }, |
38 | child: const Text('Open Modal'), |
39 | ), |
40 | ), |
41 | ); |
42 | } |
43 | |
44 | @pragma('vm:entry-point') |
45 | static Route<void> _modalBuilder(BuildContext context, Object? arguments) { |
46 | return CupertinoModalPopupRoute<void>( |
47 | builder: (BuildContext context) { |
48 | return CupertinoActionSheet( |
49 | title: const Text('Title'), |
50 | message: const Text('Message'), |
51 | actions: <CupertinoActionSheetAction>[ |
52 | CupertinoActionSheetAction( |
53 | child: const Text('Action One'), |
54 | onPressed: () { |
55 | Navigator.pop(context); |
56 | }, |
57 | ), |
58 | CupertinoActionSheetAction( |
59 | child: const Text('Action Two'), |
60 | onPressed: () { |
61 | Navigator.pop(context); |
62 | }, |
63 | ), |
64 | ], |
65 | ); |
66 | }, |
67 | ); |
68 | } |
69 | } |
70 |