|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | + |
| 3 | + |
| 4 | +class HeroDetail extends StatefulWidget { |
| 5 | + @override |
| 6 | + _HeroDetailState createState() => _HeroDetailState(); |
| 7 | +} |
| 8 | + |
| 9 | +class _HeroDetailState extends State<HeroDetail> with TickerProviderStateMixin { |
| 10 | + int _bgColor; |
| 11 | + Animation<Offset> animation; |
| 12 | + Animation<Offset> titleAnimation; |
| 13 | + Animation<Offset> detailAnimation; |
| 14 | + AnimationController backgroundAnimationController; |
| 15 | + AnimationController titleAnimationController; |
| 16 | + AnimationController detailAnimationController; |
| 17 | + CurvedAnimation curvedAnimation; |
| 18 | + Color textColor = Colors.white; |
| 19 | + |
| 20 | + @override |
| 21 | + void initState() { |
| 22 | + super.initState(); |
| 23 | +// TODO: put animation code here |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | + backgroundAnimationController = |
| 28 | + AnimationController(vsync: this, duration: Duration(milliseconds: 500)); |
| 29 | + animation = Tween<Offset>(begin: Offset(0, 0), end: Offset(0, -1.0)) |
| 30 | + .animate(backgroundAnimationController); |
| 31 | + |
| 32 | + //title animation |
| 33 | + titleAnimationController = AnimationController( |
| 34 | + vsync: this, duration: Duration(milliseconds: 1000)); |
| 35 | + curvedAnimation = CurvedAnimation( |
| 36 | + parent: titleAnimationController, curve: Curves.easeOutBack); |
| 37 | + titleAnimation = Tween<Offset>(begin: Offset(0, 0.7), end: Offset(0, 0.0)) |
| 38 | + .animate(curvedAnimation); |
| 39 | + |
| 40 | + //Detail animation |
| 41 | + detailAnimationController = |
| 42 | + AnimationController(vsync: this, duration: Duration(milliseconds: 500)); |
| 43 | + curvedAnimation = CurvedAnimation( |
| 44 | + parent: detailAnimationController, curve: Curves.easeOutBack); |
| 45 | + detailAnimation = Tween<Offset>(begin: Offset(0, 1.0), end: Offset(0, 0.0)) |
| 46 | + .animate(curvedAnimation); |
| 47 | + |
| 48 | + titleAnimationController.forward().whenComplete(() { |
| 49 | + setState(() { |
| 50 | + textColor = Colors.black; |
| 51 | + }); |
| 52 | + backgroundAnimationController.forward().whenComplete(() { |
| 53 | + detailAnimationController.forward(); |
| 54 | + }); |
| 55 | + }); |
| 56 | + } |
| 57 | + |
| 58 | + @override |
| 59 | + Widget build(BuildContext context) { |
| 60 | + TextStyle display3 = |
| 61 | + Theme.of(context).textTheme.display3.copyWith(color: textColor); |
| 62 | + TextStyle title = |
| 63 | + Theme.of(context).textTheme.title.copyWith(color: textColor); |
| 64 | + |
| 65 | + return WillPopScope( |
| 66 | + onWillPop: _onWillPop, |
| 67 | + child: Scaffold( |
| 68 | + backgroundColor: Colors.white, |
| 69 | + body: Stack( |
| 70 | + |
| 71 | + children: <Widget>[ |
| 72 | + SlideTransition( |
| 73 | + position: animation, |
| 74 | + child: Container( |
| 75 | + decoration: BoxDecoration( |
| 76 | + gradient: LinearGradient( |
| 77 | + begin: AlignmentDirectional.topCenter, |
| 78 | + end: AlignmentDirectional.bottomCenter, |
| 79 | + stops: [0.7, 1.0], |
| 80 | + colors: [Colors.grey, Colors.white70])), |
| 81 | + width: MediaQuery.of(context).size.width, |
| 82 | + height: MediaQuery.of(context).size.height, |
| 83 | + ), |
| 84 | + ), |
| 85 | + Container( |
| 86 | + padding: EdgeInsets.only(top: 34, left: 24, right: 34), |
| 87 | + child: Column( |
| 88 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 89 | + children: <Widget>[ |
| 90 | + Stack( |
| 91 | + children: <Widget>[ |
| 92 | + Hero( |
| 93 | + tag:"photo", |
| 94 | + child: Image.asset( |
| 95 | + "images/joker.jpg", |
| 96 | + height: MediaQuery.of(context).size.height * 0.5, |
| 97 | + width: MediaQuery.of(context).size.width, |
| 98 | + ), |
| 99 | + ), |
| 100 | + IconButton( |
| 101 | + icon: Icon( |
| 102 | + Icons.arrow_back_ios, |
| 103 | + color: Colors.black, |
| 104 | + size: 18, |
| 105 | + ), |
| 106 | + onPressed: () { |
| 107 | + _reverseAllAnimationAndPop(); |
| 108 | + }) |
| 109 | + ], |
| 110 | + ), |
| 111 | + SlideTransition( |
| 112 | + position: titleAnimation, |
| 113 | + child: Column( |
| 114 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 115 | + children: <Widget>[ |
| 116 | + Container( |
| 117 | + width: MediaQuery.of(context).size.width * 0.55, |
| 118 | + child: Text( |
| 119 | + "Dvm is back ", |
| 120 | + style: display3, |
| 121 | + ), |
| 122 | + ), |
| 123 | + Row( |
| 124 | + mainAxisAlignment: MainAxisAlignment.spaceBetween, |
| 125 | + children: <Widget>[ |
| 126 | + Text( |
| 127 | + "Order of the Phoenix".toLowerCase(), |
| 128 | + style: title, |
| 129 | + ), |
| 130 | + Image.asset( |
| 131 | + 'images/flutter.png', |
| 132 | + width: 60, |
| 133 | + height: 50, |
| 134 | + ) |
| 135 | + ], |
| 136 | + ) |
| 137 | + ], |
| 138 | + ), |
| 139 | + ), |
| 140 | + Expanded( |
| 141 | + child: SlideTransition( |
| 142 | + position: detailAnimation, |
| 143 | + child: Column( |
| 144 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 145 | + children: <Widget>[ |
| 146 | + Text( |
| 147 | + "Smile, because it confuses people. Smile, because it’s easier than explaining what is killing you inside. ", |
| 148 | + maxLines: 3, |
| 149 | + style: TextStyle(color: Colors.grey), |
| 150 | + ), |
| 151 | + Divider(), |
| 152 | + Text( |
| 153 | + "Made with 💙 by Divyam Joshi", |
| 154 | + style: title, |
| 155 | + ), |
| 156 | + |
| 157 | + ], |
| 158 | + ), |
| 159 | + ), |
| 160 | + ), |
| 161 | + ], |
| 162 | + ), |
| 163 | + ) |
| 164 | + ], |
| 165 | + )), |
| 166 | + ); |
| 167 | + } |
| 168 | + |
| 169 | + Future<bool> _onWillPop() { |
| 170 | + _reverseAllAnimationAndPop(); |
| 171 | + } |
| 172 | + |
| 173 | + void _reverseAllAnimationAndPop() { |
| 174 | + detailAnimationController.reverse().whenComplete(() { |
| 175 | + backgroundAnimationController.reverse().whenComplete(() { |
| 176 | + titleAnimationController.reverse().whenComplete(() { |
| 177 | + Navigator.of(context).pop(true); |
| 178 | + }); |
| 179 | + }); |
| 180 | + }); |
| 181 | + } |
| 182 | +} |
0 commit comments