Skip to content

Commit 803f995

Browse files
authored
Update Cupertino examples and add missing tests (#103128)
1 parent b05b44e commit 803f995

30 files changed

+493
-235
lines changed

examples/api/lib/cupertino/activity_indicator/cupertino_activity_indicator.0.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ class CupertinoIndicatorExample extends StatelessWidget {
2525

2626
@override
2727
Widget build(BuildContext context) {
28-
2928
return CupertinoPageScaffold(
29+
navigationBar: const CupertinoNavigationBar(
30+
middle: Text('CupertinoActivityIndicator Sample'),
31+
),
3032
child: Center(
3133
child: Column(
3234
mainAxisAlignment: MainAxisAlignment.spaceEvenly,

examples/api/lib/cupertino/button/cupertino_button.0.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class CupertinoButtonExample extends StatelessWidget {
2626
@override
2727
Widget build(BuildContext context) {
2828
return CupertinoPageScaffold(
29+
navigationBar: const CupertinoNavigationBar(
30+
middle: Text('CupertinoButton Sample'),
31+
),
2932
child: Center(
3033
child: Column(
3134
mainAxisSize: MainAxisSize.min,

examples/api/lib/cupertino/context_menu/cupertino_context_menu.0.dart

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,74 @@
55
// Flutter code sample for CupertinoContextMenu
66

77
import 'package:flutter/cupertino.dart';
8-
98
import 'package:flutter/material.dart';
109

11-
void main() => runApp(const MyApp());
12-
13-
class MyApp extends StatelessWidget {
14-
const MyApp({Key? key}) : super(key: key);
10+
void main() => runApp(const ContextMenuApp());
1511

16-
static const String _title = 'Flutter Code Sample';
12+
class ContextMenuApp extends StatelessWidget {
13+
const ContextMenuApp({Key? key}) : super(key: key);
1714

1815
@override
1916
Widget build(BuildContext context) {
20-
return const MaterialApp(
21-
title: _title,
22-
home: MyStatelessWidget(),
17+
return const CupertinoApp(
18+
theme: CupertinoThemeData(brightness: Brightness.light),
19+
home: ContextMenuExample(),
2320
);
2421
}
2522
}
2623

27-
class MyStatelessWidget extends StatelessWidget {
28-
const MyStatelessWidget({Key? key}) : super(key: key);
24+
class ContextMenuExample extends StatelessWidget {
25+
const ContextMenuExample({Key? key}) : super(key: key);
2926

3027
@override
3128
Widget build(BuildContext context) {
32-
return Scaffold(
33-
body: Center(
29+
return CupertinoPageScaffold(
30+
navigationBar: const CupertinoNavigationBar(
31+
middle: Text('CupertinoContextMenu Sample'),
32+
),
33+
child: Center(
3434
child: SizedBox(
3535
width: 100,
3636
height: 100,
3737
child: CupertinoContextMenu(
3838
actions: <Widget>[
3939
CupertinoContextMenuAction(
40-
child: const Text('Action one'),
4140
onPressed: () {
4241
Navigator.pop(context);
4342
},
43+
isDefaultAction: true,
44+
trailingIcon: CupertinoIcons.doc_on_clipboard_fill,
45+
child: const Text('Copy'),
46+
),
47+
CupertinoContextMenuAction(
48+
onPressed: () {
49+
Navigator.pop(context);
50+
},
51+
trailingIcon: CupertinoIcons.share,
52+
child: const Text('Share '),
4453
),
4554
CupertinoContextMenuAction(
46-
child: const Text('Action two'),
4755
onPressed: () {
4856
Navigator.pop(context);
4957
},
58+
trailingIcon: CupertinoIcons.heart,
59+
child: const Text('Favorite'),
60+
),
61+
CupertinoContextMenuAction(
62+
onPressed: () {
63+
Navigator.pop(context);
64+
},
65+
isDestructiveAction: true,
66+
trailingIcon: CupertinoIcons.delete,
67+
child: const Text('Delete'),
5068
),
5169
],
5270
child: Container(
53-
color: Colors.red,
71+
decoration: BoxDecoration(
72+
color: CupertinoColors.systemYellow,
73+
borderRadius: BorderRadius.circular(20.0),
74+
),
75+
child: const FlutterLogo(size: 500.0),
5476
),
5577
),
5678
),

examples/api/lib/cupertino/date_picker/cupertino_date_picker.0.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ class _DatePickerExampleState extends State<DatePickerExample> {
5757
@override
5858
Widget build(BuildContext context) {
5959
return CupertinoPageScaffold(
60+
navigationBar: const CupertinoNavigationBar(
61+
middle: Text('CupertinoDatePicker Sample'),
62+
),
6063
child: DefaultTextStyle(
6164
style: TextStyle(
6265
color: CupertinoColors.label.resolveFrom(context),

examples/api/lib/cupertino/date_picker/cupertino_timer_picker.0.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ class _TimerPickerExampleState extends State<TimerPickerExample> {
5555
@override
5656
Widget build(BuildContext context) {
5757
return CupertinoPageScaffold(
58+
navigationBar: const CupertinoNavigationBar(
59+
middle: Text('CupertinoTimerPicker Sample'),
60+
),
5861
child: DefaultTextStyle(
5962
style: TextStyle(
6063
color: CupertinoColors.label.resolveFrom(context),

examples/api/lib/cupertino/form_row/cupertino_form_row.0.dart

Lines changed: 66 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -33,74 +33,80 @@ class _CupertinoFormRowExampleState extends State<CupertinoFormRowExample> {
3333
@override
3434
Widget build(BuildContext context) {
3535
return CupertinoPageScaffold(
36-
child: CupertinoFormSection(
37-
header: const Text('Connectivity'),
38-
children: <Widget>[
39-
CupertinoFormRow(
40-
prefix: const PrefixWidget(
41-
icon: CupertinoIcons.airplane,
42-
title: 'Airplane Mode',
43-
color: CupertinoColors.systemOrange,
44-
),
45-
child: CupertinoSwitch(
46-
value: airplaneMode,
47-
onChanged: (bool value) {
48-
setState(() {
49-
airplaneMode = value;
50-
});
51-
},
52-
),
53-
),
54-
CupertinoFormRow(
55-
prefix: const PrefixWidget(
56-
icon: CupertinoIcons.wifi,
57-
title: 'Wi-Fi',
58-
color: CupertinoColors.systemBlue,
59-
),
60-
error: const Text('Home network unavailable'),
61-
child: Row(
62-
mainAxisAlignment: MainAxisAlignment.end,
63-
children: const <Widget>[
64-
Text('Not connected'),
65-
SizedBox(width: 5),
66-
Icon(CupertinoIcons.forward)
67-
],
68-
),
69-
),
70-
CupertinoFormRow(
71-
prefix: const PrefixWidget(
72-
icon: CupertinoIcons.bluetooth,
73-
title: 'Bluetooth',
74-
color: CupertinoColors.activeBlue,
36+
navigationBar: const CupertinoNavigationBar(
37+
middle: Text('CupertinoFormSection Sample'),
38+
),
39+
// Add safe area widget to place the CupertinoFormSection below the navigation bar.
40+
child: SafeArea(
41+
child: CupertinoFormSection(
42+
header: const Text('Connectivity'),
43+
children: <Widget>[
44+
CupertinoFormRow(
45+
prefix: const PrefixWidget(
46+
icon: CupertinoIcons.airplane,
47+
title: 'Airplane Mode',
48+
color: CupertinoColors.systemOrange,
49+
),
50+
child: CupertinoSwitch(
51+
value: airplaneMode,
52+
onChanged: (bool value) {
53+
setState(() {
54+
airplaneMode = value;
55+
});
56+
},
57+
),
7558
),
76-
helper: Padding(
77-
padding: const EdgeInsets.symmetric(vertical: 4.0),
59+
CupertinoFormRow(
60+
prefix: const PrefixWidget(
61+
icon: CupertinoIcons.wifi,
62+
title: 'Wi-Fi',
63+
color: CupertinoColors.systemBlue,
64+
),
65+
error: const Text('Home network unavailable'),
7866
child: Row(
79-
mainAxisAlignment: MainAxisAlignment.spaceBetween,
67+
mainAxisAlignment: MainAxisAlignment.end,
8068
children: const <Widget>[
81-
Text('Headphone'),
82-
Text('Connected'),
69+
Text('Not connected'),
70+
SizedBox(width: 5),
71+
Icon(CupertinoIcons.forward)
8372
],
8473
),
8574
),
86-
child: Row(
87-
mainAxisAlignment: MainAxisAlignment.end,
88-
children: const <Widget>[
89-
Text('On'),
90-
SizedBox(width: 5),
91-
Icon(CupertinoIcons.forward)
92-
],
75+
CupertinoFormRow(
76+
prefix: const PrefixWidget(
77+
icon: CupertinoIcons.bluetooth,
78+
title: 'Bluetooth',
79+
color: CupertinoColors.activeBlue,
80+
),
81+
helper: Padding(
82+
padding: const EdgeInsets.symmetric(vertical: 4.0),
83+
child: Row(
84+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
85+
children: const <Widget>[
86+
Text('Headphone'),
87+
Text('Connected'),
88+
],
89+
),
90+
),
91+
child: Row(
92+
mainAxisAlignment: MainAxisAlignment.end,
93+
children: const <Widget>[
94+
Text('On'),
95+
SizedBox(width: 5),
96+
Icon(CupertinoIcons.forward)
97+
],
98+
),
9399
),
94-
),
95-
const CupertinoFormRow(
96-
prefix: PrefixWidget(
97-
icon: CupertinoIcons.bluetooth,
98-
title: 'Mobile Data',
99-
color: CupertinoColors.systemGreen,
100+
const CupertinoFormRow(
101+
prefix: PrefixWidget(
102+
icon: CupertinoIcons.bluetooth,
103+
title: 'Mobile Data',
104+
color: CupertinoColors.systemGreen,
105+
),
106+
child: Icon(CupertinoIcons.forward),
100107
),
101-
child: Icon(CupertinoIcons.forward),
102-
),
103-
],
108+
],
109+
),
104110
),
105111
);
106112
}

examples/api/lib/cupertino/page_scaffold/cupertino_page_scaffold.0.dart

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,28 @@
66

77
import 'package:flutter/cupertino.dart';
88

9-
void main() => runApp(const MyApp());
9+
void main() => runApp(const PageScaffoldApp());
1010

11-
class MyApp extends StatelessWidget {
12-
const MyApp({Key? key}) : super(key: key);
13-
14-
static const String _title = 'Flutter Code Sample';
11+
class PageScaffoldApp extends StatelessWidget {
12+
const PageScaffoldApp({Key? key}) : super(key: key);
1513

1614
@override
1715
Widget build(BuildContext context) {
1816
return const CupertinoApp(
19-
title: _title,
20-
home: MyStatefulWidget(),
17+
theme: CupertinoThemeData(brightness: Brightness.light),
18+
home: PageScaffoldExample(),
2119
);
2220
}
2321
}
2422

25-
class MyStatefulWidget extends StatefulWidget {
26-
const MyStatefulWidget({Key? key}) : super(key: key);
23+
class PageScaffoldExample extends StatefulWidget {
24+
const PageScaffoldExample({Key? key}) : super(key: key);
2725

2826
@override
29-
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
27+
State<PageScaffoldExample> createState() => _PageScaffoldExampleState();
3028
}
3129

32-
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
30+
class _PageScaffoldExampleState extends State<PageScaffoldExample> {
3331
int _count = 0;
3432

3533
@override
@@ -38,18 +36,24 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget> {
3836
// Uncomment to change the background color
3937
// backgroundColor: CupertinoColors.systemPink,
4038
navigationBar: const CupertinoNavigationBar(
41-
middle: Text('Sample Code'),
39+
middle: Text('CupertinoPageScaffold Sample'),
4240
),
43-
child: ListView(
44-
children: <Widget>[
45-
CupertinoButton(
46-
onPressed: () => setState(() => _count++),
47-
child: const Icon(CupertinoIcons.add),
48-
),
49-
Center(
50-
child: Text('You have pressed the button $_count times.'),
51-
),
52-
],
41+
child: Center(
42+
child: Column(
43+
mainAxisAlignment: MainAxisAlignment.center,
44+
children: <Widget>[
45+
Center(
46+
child: Text('You have pressed the button $_count times.'),
47+
),
48+
const SizedBox(height: 20.0),
49+
Center(
50+
child: CupertinoButton.filled(
51+
onPressed: () => setState(() => _count++),
52+
child: const Icon(CupertinoIcons.add),
53+
),
54+
),
55+
],
56+
),
5357
),
5458
);
5559
}

examples/api/lib/cupertino/picker/cupertino_picker.0.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ class _CupertinoPickerExampleState extends State<CupertinoPickerExample> {
6464
@override
6565
Widget build(BuildContext context) {
6666
return CupertinoPageScaffold(
67+
navigationBar: const CupertinoNavigationBar(
68+
middle: Text('CupertinoPicker Sample'),
69+
),
6770
child: DefaultTextStyle(
6871
style: TextStyle(
6972
color: CupertinoColors.label.resolveFrom(context),

0 commit comments

Comments
 (0)