路由生命周期状态
This commit is contained in:
107
lib/10/cupertino_context_menu_demo.dart
Normal file
107
lib/10/cupertino_context_menu_demo.dart
Normal file
@@ -0,0 +1,107 @@
|
||||
// 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/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Flutter code sample for [CupertinoContextMenu].
|
||||
|
||||
final DecorationTween _tween = DecorationTween(
|
||||
begin: BoxDecoration(
|
||||
color: CupertinoColors.systemPurple,
|
||||
boxShadow: const <BoxShadow>[],
|
||||
borderRadius: BorderRadius.circular(20.0),
|
||||
),
|
||||
end: BoxDecoration(
|
||||
color: CupertinoColors.systemPurple,
|
||||
boxShadow: CupertinoContextMenu.kEndBoxShadow,
|
||||
borderRadius: BorderRadius.circular(20.0),
|
||||
),
|
||||
);
|
||||
|
||||
class CupertinoContextMenuDemo extends StatelessWidget {
|
||||
const CupertinoContextMenuDemo({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 案例'),
|
||||
),
|
||||
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(
|
||||
padding: EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: CupertinoColors.systemPurple,
|
||||
borderRadius: BorderRadius.circular(20.0),
|
||||
),
|
||||
child: const FlutterLogo(size: 250.0),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user