@@ -14,13 +14,14 @@ class FadeScaleTransitionDemo extends StatefulWidget {
1414
1515class _FadeScaleTransitionDemoState extends State <FadeScaleTransitionDemo >
1616 with SingleTickerProviderStateMixin {
17- AnimationController controller ;
17+ AnimationController _controller ;
1818
19- bool shouldEnter = true ;
19+ bool _showFab = true ;
2020
2121 @override
2222 void initState () {
23- controller = AnimationController (
23+ _controller = AnimationController (
24+ value: 1.0 ,
2425 duration: const Duration (milliseconds: 150 ),
2526 reverseDuration: const Duration (milliseconds: 75 ),
2627 vsync: this ,
@@ -30,72 +31,66 @@ class _FadeScaleTransitionDemoState extends State<FadeScaleTransitionDemo>
3031
3132 @override
3233 void dispose () {
33- controller .dispose ();
34+ _controller .dispose ();
3435 super .dispose ();
3536 }
3637
37- void updateAnimationController () {
38- switch (controller.status) {
39- case AnimationStatus .completed:
40- case AnimationStatus .forward:
41- controller.reverse ();
42- setState (() {
43- shouldEnter = true ;
44- });
45- break ;
46- case AnimationStatus .dismissed:
47- case AnimationStatus .reverse:
48- controller.forward ();
49- setState (() {
50- shouldEnter = false ;
51- });
52- break ;
53- }
54- }
55-
5638 @override
5739 Widget build (BuildContext context) {
5840 return Scaffold (
5941 appBar: AppBar (
6042 title: const Text ('Fade Transition Demo' ),
6143 ),
62- body: Column (
63- children: < Widget > [
64- Expanded (
65- child: ListView (
66- children: < Widget > [
67- SizedBox (
68- height: 200 ,
69- child: Center (
70- child: FadeScaleTransition (
71- animation: controller,
72- child: _ExampleAlertDialog (),
73- ),
74- ),
75- ),
76- ],
77- ),
78- ),
79- const Divider (thickness: 2.0 ),
80- Padding (
81- padding: const EdgeInsets .only (
82- bottom: 8.0 ,
44+ floatingActionButton: AnimatedBuilder (
45+ animation: _controller,
46+ builder: (BuildContext context, Widget child) {
47+ return FadeScaleTransition (
48+ animation: _controller,
49+ child: child,
50+ );
51+ },
52+ child: FloatingActionButton (
53+ child: Icon (Icons .add),
54+ onPressed: () {},
55+ ),
56+ ),
57+ body: Center (
58+ child: Column (
59+ mainAxisSize: MainAxisSize .min,
60+ children: < Widget > [
61+ RaisedButton (
62+ onPressed: () {
63+ if (_showFab) {
64+ setState (() {
65+ _showFab = false ;
66+ });
67+ _controller.reverse ();
68+ } else {
69+ setState (() {
70+ _showFab = true ;
71+ });
72+ _controller.forward ();
73+ }
74+ },
75+ color: Theme .of (context).colorScheme.primary,
76+ textColor: Theme .of (context).colorScheme.onPrimary,
77+ child: _showFab ? const Text ('HIDE FAB' ) : const Text ('SHOW FAB' ),
8378 ),
84- child : Row (
85- mainAxisAlignment : MainAxisAlignment .center,
86- children : < Widget > [
87- RaisedButton (
88- onPressed : updateAnimationController ,
89- color : Theme . of ( context).colorScheme.primary,
90- textColor : Theme . of (context).colorScheme.onPrimary,
91- child : shouldEnter
92- ? const Text ( 'FADE ENTER' )
93- : const Text ( 'FADE EXIT' ) ,
94- ) ,
95- ] ,
79+ RaisedButton (
80+ onPressed : () {
81+ showModal < void >(
82+ context : context,
83+ configuration : FadeScaleTransitionConfiguration () ,
84+ builder : ( BuildContext context) {
85+ return _ExampleAlertDialog ();
86+ });
87+ },
88+ color : Theme . of (context).colorScheme.primary ,
89+ textColor : Theme . of (context).colorScheme.onPrimary ,
90+ child : const Text ( 'SHOW MODAL' ) ,
9691 ),
97- ) ,
98- ] ,
92+ ] ,
93+ ) ,
9994 ),
10095 );
10196 }
@@ -108,11 +103,15 @@ class _ExampleAlertDialog extends StatelessWidget {
108103 content: const Text ('Alert Dialog' ),
109104 actions: < Widget > [
110105 FlatButton (
111- onPressed: () {},
106+ onPressed: () {
107+ Navigator .of (context).pop ();
108+ },
112109 child: const Text ('CANCEL' ),
113110 ),
114111 FlatButton (
115- onPressed: () {},
112+ onPressed: () {
113+ Navigator .of (context).pop ();
114+ },
116115 child: const Text ('DISCARD' ),
117116 ),
118117 ],
0 commit comments