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/cupertino.dart';
6
7/// Flutter code sample for [showCupertinoSheet].
8
9void main() {
10 runApp(const CupertinoSheetApp());
11}
12
13class CupertinoSheetApp extends StatelessWidget {
14 const CupertinoSheetApp({super.key});
15
16 @override
17 Widget build(BuildContext context) {
18 return const CupertinoApp(title: 'Cupertino Sheet', home: HomePage());
19 }
20}
21
22class HomePage extends StatelessWidget {
23 const HomePage({super.key});
24
25 @override
26 Widget build(BuildContext context) {
27 return CupertinoPageScaffold(
28 navigationBar: const CupertinoNavigationBar(
29 middle: Text('Sheet Example'),
30 automaticBackgroundVisibility: false,
31 ),
32 child: Center(
33 child: Column(
34 mainAxisAlignment: MainAxisAlignment.center,
35 children: <Widget>[
36 CupertinoButton.filled(
37 onPressed: () {
38 showCupertinoSheet<void>(
39 context: context,
40 useNestedNavigation: true,
41 pageBuilder: (BuildContext context) => const _SheetScaffold(),
42 );
43 },
44 child: const Text('Open Bottom Sheet'),
45 ),
46 ],
47 ),
48 ),
49 );
50 }
51}
52
53class _SheetScaffold extends StatelessWidget {
54 const _SheetScaffold();
55
56 @override
57 Widget build(BuildContext context) {
58 return const CupertinoPageScaffold(child: _SheetBody(title: 'CupertinoSheetRoute'));
59 }
60}
61
62class _SheetBody extends StatelessWidget {
63 const _SheetBody({required this.title});
64
65 final String title;
66
67 @override
68 Widget build(BuildContext context) {
69 return Center(
70 child: Column(
71 mainAxisAlignment: MainAxisAlignment.center,
72 children: <Widget>[
73 Text(title),
74 CupertinoButton.filled(
75 onPressed: () {
76 Navigator.of(context).pop();
77 },
78 child: const Text('Go Back'),
79 ),
80 CupertinoButton.filled(
81 onPressed: () {
82 CupertinoSheetRoute.popSheet(context);
83 },
84 child: const Text('Pop Whole Sheet'),
85 ),
86 CupertinoButton.filled(
87 onPressed: () {
88 Navigator.of(context).push(
89 CupertinoPageRoute<void>(builder: (BuildContext context) => const _SheetNextPage()),
90 );
91 },
92 child: const Text('Push Nested Page'),
93 ),
94 CupertinoButton.filled(
95 onPressed: () {
96 showCupertinoSheet<void>(
97 context: context,
98 useNestedNavigation: true,
99 pageBuilder: (BuildContext context) => const _SheetScaffold(),
100 );
101 },
102 child: const Text('Push Another Sheet'),
103 ),
104 ],
105 ),
106 );
107 }
108}
109
110class _SheetNextPage extends StatelessWidget {
111 const _SheetNextPage();
112
113 @override
114 Widget build(BuildContext context) {
115 return const CupertinoPageScaffold(
116 backgroundColor: CupertinoColors.activeOrange,
117 child: _SheetBody(title: 'Next Page'),
118 );
119 }
120}
121

Provided by KDAB

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