Skip to content

Commit 992e804

Browse files
authored
Merge pull request FlutterOpen#38 from FlutterOpen/dev
add the AnimatedModalBarrier.
2 parents 9bbebf9 + 571f67f commit 992e804

File tree

5 files changed

+74
-0
lines changed

5 files changed

+74
-0
lines changed

lib/const/page_item_const.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,9 @@ const PAGE_ITEMS = [
227227
"img": PageImage.FLUTTER_OPEN,
228228
"click": PageName.ANIM_LIST,
229229
},
230+
{
231+
"title": PageName.ANIM_MODAL_BARRIER,
232+
"img": PageImage.FLUTTER_OPEN,
233+
"click": PageName.ANIM_MODAL_BARRIER,
234+
},
230235
];

lib/const/page_name_const.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,5 @@ class PageName {
5050
static const ANIM_ROTATION = "RotationTransition";
5151
static const ANIM_DEFAULT_TEXT = "DefaultText";
5252
static const ANIM_LIST = "AnimationList";
53+
static const ANIM_MODAL_BARRIER = "AnimatedModalBarrier";
5354
}

lib/main.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class FlutterOpenApp extends StatelessWidget {
6464
PageName.ANIM_ROTATION: (context) => RotationPage(),
6565
PageName.ANIM_DEFAULT_TEXT: (context) => DefaultTextPage(),
6666
PageName.ANIM_LIST: (context) => AnimListPage(),
67+
PageName.ANIM_MODAL_BARRIER: (context) => AnimatedModalPage(),
6768
},
6869
);
6970
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
///
2+
/// Created by NieBin on 2019/6/10
3+
/// Github: https://github.com/nb312
4+
5+
///
6+
import "package:flutter/material.dart";
7+
import 'package:flutter_widgets/const/_const.dart';
8+
9+
class AnimatedModalPage extends StatefulWidget {
10+
@override
11+
_AnimatedModalState createState() => _AnimatedModalState();
12+
}
13+
14+
class _AnimatedModalState extends State<AnimatedModalPage>
15+
with SingleTickerProviderStateMixin {
16+
Animation<Color> _animation;
17+
AnimationController _controller;
18+
bool _isClick = false;
19+
20+
Widget _modalBarrier() => Container(
21+
constraints: BoxConstraints.expand(height: 100, width: 100),
22+
child: Stack(
23+
children: <Widget>[
24+
AnimatedModalBarrier(
25+
color: _animation,
26+
),
27+
Text("Click Me finsih this page!")
28+
],
29+
),
30+
);
31+
32+
@override
33+
void initState() {
34+
_controller = AnimationController(
35+
vsync: this,
36+
duration: Duration(seconds: 2),
37+
);
38+
CurvedAnimation curve =
39+
CurvedAnimation(parent: _controller, curve: Curves.easeIn);
40+
_animation = Tween(begin: BLUE_DEEP, end: RED_LIGHT).animate(curve);
41+
super.initState();
42+
}
43+
44+
@override
45+
Widget build(BuildContext context) {
46+
return Scaffold(
47+
appBar: AppBar(
48+
title: Text(""),
49+
),
50+
body: Column(
51+
children: <Widget>[
52+
_modalBarrier(),
53+
FloatingActionButton(
54+
child: Text("Click"),
55+
onPressed: () {
56+
setState(() {
57+
_isClick = !_isClick;
58+
});
59+
_controller.reset();
60+
_controller.forward();
61+
},
62+
)
63+
],
64+
));
65+
}
66+
}

lib/page/anim/_anim.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ export 'PositionTransitionPage.dart';
1111
export 'RotationPage.dart';
1212
export 'DefaultTextPage.dart';
1313
export 'AnimListPage.dart';
14+
export 'AnimatedModalPage.dart';

0 commit comments

Comments
 (0)