Skip to content

Commit 97195d1

Browse files
Update CupertinoContextMenu to iOS 16 visuals (#110616)
* Update CupertinoContextMenu to iOS 16 visuals * Revert some formatting * Remove space * Remove formatting changes, add more comments * Added shadow effect * Update context menu tests * Remove white spaces * Remove unused variable * Refactor type checking logic * Set default previewBuilder and update tests * Check for border radius * Remove trailing spaces * Add builder to constructor * Update previewBuilder Rebase to master * Update builder and tests * Remove trailing spaces * Update examples * Refactor builder * Update builder to use one animation * Update scale * Change deprecation message, remove white spaces * Change deprecation message * Change deprecation message * Change deprecation message * Update documentation * Update documentation * Update documentation and examples * Update documentation and examples * Remove white spaces * Remove white spaces * Remove const * Address linting errors * Seperate builder into own constructor * Remove trailing characters * Formatting changes * Remove white spaces * Change ignore comment * Add TODO * Remove whitespace
1 parent 7802c7a commit 97195d1

File tree

5 files changed

+652
-141
lines changed

5 files changed

+652
-141
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class ContextMenuExample extends StatelessWidget {
4949
Navigator.pop(context);
5050
},
5151
trailingIcon: CupertinoIcons.share,
52-
child: const Text('Share '),
52+
child: const Text('Share'),
5353
),
5454
CupertinoContextMenuAction(
5555
onPressed: () {
@@ -68,10 +68,7 @@ class ContextMenuExample extends StatelessWidget {
6868
),
6969
],
7070
child: Container(
71-
decoration: BoxDecoration(
72-
color: CupertinoColors.systemYellow,
73-
borderRadius: BorderRadius.circular(20.0),
74-
),
71+
color: CupertinoColors.systemYellow,
7572
child: const FlutterLogo(size: 500.0),
7673
),
7774
),
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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+
/// Flutter code sample for [CupertinoContextMenu].
6+
7+
import 'package:flutter/cupertino.dart';
8+
import 'package:flutter/material.dart';
9+
10+
final DecorationTween _tween = DecorationTween(
11+
begin: BoxDecoration(
12+
color: CupertinoColors.systemYellow,
13+
boxShadow: const <BoxShadow>[],
14+
borderRadius: BorderRadius.circular(20.0),
15+
),
16+
end: BoxDecoration(
17+
color: CupertinoColors.systemYellow,
18+
boxShadow: CupertinoContextMenu.kEndBoxShadow,
19+
borderRadius: BorderRadius.circular(20.0),
20+
),
21+
);
22+
23+
void main() => runApp(const ContextMenuApp());
24+
25+
class ContextMenuApp extends StatelessWidget {
26+
const ContextMenuApp({super.key});
27+
28+
@override
29+
Widget build(BuildContext context) {
30+
return const CupertinoApp(
31+
theme: CupertinoThemeData(brightness: Brightness.light),
32+
home: ContextMenuExample(),
33+
);
34+
}
35+
}
36+
37+
class ContextMenuExample extends StatelessWidget {
38+
const ContextMenuExample({super.key});
39+
40+
// Or just do this inline in the builder below?
41+
static Animation<Decoration> _boxDecorationAnimation(Animation<double> animation) {
42+
return _tween.animate(
43+
CurvedAnimation(
44+
parent: animation,
45+
curve: Interval(
46+
0.0,
47+
CupertinoContextMenu.animationOpensAt,
48+
),
49+
),
50+
);
51+
}
52+
53+
@override
54+
Widget build(BuildContext context) {
55+
return CupertinoPageScaffold(
56+
navigationBar: const CupertinoNavigationBar(
57+
middle: Text('CupertinoContextMenu Sample'),
58+
),
59+
child: Center(
60+
child: SizedBox(
61+
width: 100,
62+
height: 100,
63+
child: CupertinoContextMenu.builder(
64+
actions: <Widget>[
65+
CupertinoContextMenuAction(
66+
onPressed: () {
67+
Navigator.pop(context);
68+
},
69+
isDefaultAction: true,
70+
trailingIcon: CupertinoIcons.doc_on_clipboard_fill,
71+
child: const Text('Copy'),
72+
),
73+
CupertinoContextMenuAction(
74+
onPressed: () {
75+
Navigator.pop(context);
76+
},
77+
trailingIcon: CupertinoIcons.share,
78+
child: const Text('Share'),
79+
),
80+
CupertinoContextMenuAction(
81+
onPressed: () {
82+
Navigator.pop(context);
83+
},
84+
trailingIcon: CupertinoIcons.heart,
85+
child: const Text('Favorite'),
86+
),
87+
CupertinoContextMenuAction(
88+
onPressed: () {
89+
Navigator.pop(context);
90+
},
91+
isDestructiveAction: true,
92+
trailingIcon: CupertinoIcons.delete,
93+
child: const Text('Delete'),
94+
),
95+
],
96+
builder:(BuildContext context, Animation<double> animation) {
97+
final Animation<Decoration> boxDecorationAnimation =
98+
_boxDecorationAnimation(animation);
99+
100+
return Container(
101+
decoration:
102+
animation.value < CupertinoContextMenu.animationOpensAt
103+
? boxDecorationAnimation.value
104+
: null,
105+
child: Container(
106+
decoration: BoxDecoration(
107+
color: CupertinoColors.systemYellow,
108+
borderRadius: BorderRadius.circular(20.0),
109+
),
110+
child: const FlutterLogo(size: 500.0),
111+
),
112+
);
113+
},
114+
),
115+
),
116+
),
117+
);
118+
}
119+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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/material.dart';
6+
import 'package:flutter_api_samples/cupertino/context_menu/cupertino_context_menu.1.dart' as example;
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
void main() {
10+
testWidgets('Can open cupertino context menu', (WidgetTester tester) async {
11+
await tester.pumpWidget(
12+
const example.ContextMenuApp(),
13+
);
14+
15+
final Offset logo = tester.getCenter(find.byType(FlutterLogo));
16+
expect(find.text('Favorite'), findsNothing);
17+
18+
await tester.startGesture(logo);
19+
await tester.pumpAndSettle();
20+
expect(find.text('Favorite'), findsOneWidget);
21+
22+
await tester.tap(find.text('Favorite'));
23+
await tester.pumpAndSettle();
24+
expect(find.text('Favorite'), findsNothing);
25+
});
26+
}

0 commit comments

Comments
 (0)