This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
7802c7a
commit 97195d1
Showing
5 changed files
with
652 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
examples/api/lib/cupertino/context_menu/cupertino_context_menu.1.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// Copyright 2014 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
/// Flutter code sample for [CupertinoContextMenu]. | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
final DecorationTween _tween = DecorationTween( | ||
begin: BoxDecoration( | ||
color: CupertinoColors.systemYellow, | ||
boxShadow: const <BoxShadow>[], | ||
borderRadius: BorderRadius.circular(20.0), | ||
), | ||
end: BoxDecoration( | ||
color: CupertinoColors.systemYellow, | ||
boxShadow: CupertinoContextMenu.kEndBoxShadow, | ||
borderRadius: BorderRadius.circular(20.0), | ||
), | ||
); | ||
|
||
void main() => runApp(const ContextMenuApp()); | ||
|
||
class ContextMenuApp extends StatelessWidget { | ||
const ContextMenuApp({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return const CupertinoApp( | ||
theme: CupertinoThemeData(brightness: Brightness.light), | ||
home: ContextMenuExample(), | ||
); | ||
} | ||
} | ||
|
||
class ContextMenuExample extends StatelessWidget { | ||
const ContextMenuExample({super.key}); | ||
|
||
// Or just do this inline in the builder below? | ||
static Animation<Decoration> _boxDecorationAnimation(Animation<double> animation) { | ||
return _tween.animate( | ||
CurvedAnimation( | ||
parent: animation, | ||
curve: Interval( | ||
0.0, | ||
CupertinoContextMenu.animationOpensAt, | ||
), | ||
), | ||
); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return CupertinoPageScaffold( | ||
navigationBar: const CupertinoNavigationBar( | ||
middle: Text('CupertinoContextMenu Sample'), | ||
), | ||
child: Center( | ||
child: SizedBox( | ||
width: 100, | ||
height: 100, | ||
child: CupertinoContextMenu.builder( | ||
actions: <Widget>[ | ||
CupertinoContextMenuAction( | ||
onPressed: () { | ||
Navigator.pop(context); | ||
}, | ||
isDefaultAction: true, | ||
trailingIcon: CupertinoIcons.doc_on_clipboard_fill, | ||
child: const Text('Copy'), | ||
), | ||
CupertinoContextMenuAction( | ||
onPressed: () { | ||
Navigator.pop(context); | ||
}, | ||
trailingIcon: CupertinoIcons.share, | ||
child: const Text('Share'), | ||
), | ||
CupertinoContextMenuAction( | ||
onPressed: () { | ||
Navigator.pop(context); | ||
}, | ||
trailingIcon: CupertinoIcons.heart, | ||
child: const Text('Favorite'), | ||
), | ||
CupertinoContextMenuAction( | ||
onPressed: () { | ||
Navigator.pop(context); | ||
}, | ||
isDestructiveAction: true, | ||
trailingIcon: CupertinoIcons.delete, | ||
child: const Text('Delete'), | ||
), | ||
], | ||
builder:(BuildContext context, Animation<double> animation) { | ||
final Animation<Decoration> boxDecorationAnimation = | ||
_boxDecorationAnimation(animation); | ||
|
||
return Container( | ||
decoration: | ||
animation.value < CupertinoContextMenu.animationOpensAt | ||
? boxDecorationAnimation.value | ||
: null, | ||
child: Container( | ||
decoration: BoxDecoration( | ||
color: CupertinoColors.systemYellow, | ||
borderRadius: BorderRadius.circular(20.0), | ||
), | ||
child: const FlutterLogo(size: 500.0), | ||
), | ||
); | ||
}, | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
examples/api/test/cupertino/context_menu/cupertino_context_menu.1_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2014 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_api_samples/cupertino/context_menu/cupertino_context_menu.1.dart' as example; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
testWidgets('Can open cupertino context menu', (WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
const example.ContextMenuApp(), | ||
); | ||
|
||
final Offset logo = tester.getCenter(find.byType(FlutterLogo)); | ||
expect(find.text('Favorite'), findsNothing); | ||
|
||
await tester.startGesture(logo); | ||
await tester.pumpAndSettle(); | ||
expect(find.text('Favorite'), findsOneWidget); | ||
|
||
await tester.tap(find.text('Favorite')); | ||
await tester.pumpAndSettle(); | ||
expect(find.text('Favorite'), findsNothing); | ||
}); | ||
} |
Oops, something went wrong.