From e16bf97398249e15342a276f2497a94bd94c32bc Mon Sep 17 00:00:00 2001 From: 28JayG Date: Sat, 23 Feb 2019 23:54:57 +0530 Subject: [PATCH 1/9] Animated Container is ready --- lib/main.dart | 108 +++++++++++++++++++------------------------------- 1 file changed, 40 insertions(+), 68 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 94b23e9..71ec1db 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -2,108 +2,80 @@ import 'package:flutter/material.dart'; void main() => runApp(new MyApp()); +const Duration duration = Duration( + milliseconds: 500, +); + class MyApp extends StatelessWidget { // This widget is the root of your application. @override Widget build(BuildContext context) { return new MaterialApp( title: 'Flutter Demo', - theme: new ThemeData( - // This is the theme of your application. - // - // Try running your application with "flutter run". You'll see the - // application has a blue toolbar. Then, without quitting the app, try - // changing the primarySwatch below to Colors.green and then invoke - // "hot reload" (press "r" in the console where you ran "flutter run", - // or press Run > Flutter Hot Reload in IntelliJ). Notice that the - // counter didn't reset back to zero; the application is not restarted. - primarySwatch: Colors.blue, - ), - home: new MyHomePage(title: 'Flutter Demo Home Page'), + home: new MyHomePage(title: 'Animations'), ); } } class MyHomePage extends StatefulWidget { MyHomePage({Key key, this.title}) : super(key: key); - - // This widget is the home page of your application. It is stateful, meaning - // that it has a State object (defined below) that contains fields that affect - // how it looks. - - // This class is the configuration for the state. It holds the values (in this - // case the title) provided by the parent (in this case the App widget) and - // used by the build method of the State. Fields in a Widget subclass are - // always marked "final". - final String title; @override _MyHomePageState createState() => new _MyHomePageState(); } -class _MyHomePageState extends State { - int _counter = 0; +class _MyHomePageState extends State with TickerProviderStateMixin { + double height; + double width; + Color color; + BoxShape boxShape = BoxShape.rectangle; + bool isCircle; - void _incrementCounter() { + @override + void initState() { + super.initState(); + height = 100.0; + width = 100.0; + color = Colors.blue; + isCircle = false; + } + + _toggle() { setState(() { - // This call to setState tells the Flutter framework that something has - // changed in this State, which causes it to rerun the build method below - // so that the display can reflect the updated values. If we changed - // _counter without calling setState(), then the build method would not be - // called again, and so nothing would appear to happen. - _counter++; + boxShape = isCircle ? BoxShape.circle : BoxShape.rectangle; + height = isCircle ? 400.0 : 100.0; + width = isCircle ? 400.0 : 100.0; + color = isCircle ? Colors.red : Colors.blue; }); } @override Widget build(BuildContext context) { - // This method is rerun every time setState is called, for instance as done - // by the _incrementCounter method above. - // - // The Flutter framework has been optimized to make rerunning build methods - // fast, so that you can just rebuild anything that needs updating rather - // than having to individually change instances of widgets. return new Scaffold( appBar: new AppBar( - // Here we take the value from the MyHomePage object that was created by - // the App.build method, and use it to set our appbar title. title: new Text(widget.title), ), body: new Center( - // Center is a layout widget. It takes a single child and positions it - // in the middle of the parent. - child: new Column( - // Column is also layout widget. It takes a list of children and - // arranges them vertically. By default, it sizes itself to fit its - // children horizontally, and tries to be as tall as its parent. - // - // Invoke "debug paint" (press "p" in the console where you ran - // "flutter run", or select "Toggle Debug Paint" from the Flutter tool - // window in IntelliJ) to see the wireframe for each widget. - // - // Column has various properties to control how it sizes itself and - // how it positions its children. Here we use mainAxisAlignment to - // center the children vertically; the main axis here is the vertical - // axis because Columns are vertical (the cross axis would be - // horizontal). - mainAxisAlignment: MainAxisAlignment.center, - children: [ - new Text( - 'You have pushed the button this many times:', - ), - new Text( - '$_counter', - style: Theme.of(context).textTheme.display1, - ), - ], + child: AnimatedContainer( + curve: Curves.decelerate, + duration: duration, + width: width, + height: height, + decoration: BoxDecoration( + color: color, + shape: boxShape, + ), ), ), floatingActionButton: new FloatingActionButton( - onPressed: _incrementCounter, - tooltip: 'Increment', + onPressed: () { + isCircle = !isCircle; + _toggle(); + }, + tooltip: 'Animate', child: new Icon(Icons.add), - ), // This trailing comma makes auto-formatting nicer for build methods. + ), ); } } From 35360157737e1fa5f0f9d1d84622d96c031626ac Mon Sep 17 00:00:00 2001 From: 28JayG Date: Sun, 24 Feb 2019 00:33:14 +0530 Subject: [PATCH 2/9] abstracts the code --- lib/main.dart | 67 +--------------------------------------- lib/res/home_page.dart | 69 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 66 deletions(-) create mode 100644 lib/res/home_page.dart diff --git a/lib/main.dart b/lib/main.dart index 71ec1db..4e305b7 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,13 +1,10 @@ +import 'package:animations/res/home_page.dart'; import 'package:flutter/material.dart'; void main() => runApp(new MyApp()); -const Duration duration = Duration( - milliseconds: 500, -); class MyApp extends StatelessWidget { - // This widget is the root of your application. @override Widget build(BuildContext context) { return new MaterialApp( @@ -17,65 +14,3 @@ class MyApp extends StatelessWidget { } } -class MyHomePage extends StatefulWidget { - MyHomePage({Key key, this.title}) : super(key: key); - final String title; - - @override - _MyHomePageState createState() => new _MyHomePageState(); -} - -class _MyHomePageState extends State with TickerProviderStateMixin { - double height; - double width; - Color color; - BoxShape boxShape = BoxShape.rectangle; - bool isCircle; - - @override - void initState() { - super.initState(); - height = 100.0; - width = 100.0; - color = Colors.blue; - isCircle = false; - } - - _toggle() { - setState(() { - boxShape = isCircle ? BoxShape.circle : BoxShape.rectangle; - height = isCircle ? 400.0 : 100.0; - width = isCircle ? 400.0 : 100.0; - color = isCircle ? Colors.red : Colors.blue; - }); - } - - @override - Widget build(BuildContext context) { - return new Scaffold( - appBar: new AppBar( - title: new Text(widget.title), - ), - body: new Center( - child: AnimatedContainer( - curve: Curves.decelerate, - duration: duration, - width: width, - height: height, - decoration: BoxDecoration( - color: color, - shape: boxShape, - ), - ), - ), - floatingActionButton: new FloatingActionButton( - onPressed: () { - isCircle = !isCircle; - _toggle(); - }, - tooltip: 'Animate', - child: new Icon(Icons.add), - ), - ); - } -} diff --git a/lib/res/home_page.dart b/lib/res/home_page.dart new file mode 100644 index 0000000..37bc4bc --- /dev/null +++ b/lib/res/home_page.dart @@ -0,0 +1,69 @@ +import 'package:flutter/material.dart'; + + +const Duration duration = Duration( + milliseconds: 600, +); + +class MyHomePage extends StatefulWidget { + MyHomePage({Key key, this.title}) : super(key: key); + final String title; + + @override + _MyHomePageState createState() => new _MyHomePageState(); +} + +class _MyHomePageState extends State with TickerProviderStateMixin { + double height; + double width; + Color color; + BoxShape boxShape = BoxShape.rectangle; + bool isCircle; + + @override + void initState() { + super.initState(); + height = 100.0; + width = 100.0; + color = Colors.blue; + isCircle = false; + } + + _toggle() { + setState(() { + boxShape = isCircle ? BoxShape.circle : BoxShape.rectangle; + height = isCircle ? 400.0 : 100.0; + width = isCircle ? 400.0 : 100.0; + color = isCircle ? Colors.red : Colors.blue; + }); + } + + @override + Widget build(BuildContext context) { + return new Scaffold( + appBar: new AppBar( + title: new Text(widget.title), + ), + body: new Center( + child: AnimatedContainer( + curve: Curves.fastOutSlowIn, + duration: duration, + width: width, + height: height, + decoration: BoxDecoration( + color: color, +// shape: boxShape, + ), + ), + ), + floatingActionButton: new FloatingActionButton( + onPressed: () { + isCircle = !isCircle; + _toggle(); + }, + tooltip: 'Animate', + child: new Icon(Icons.add), + ), + ); + } +} From 26bbf6050b40fa312adc5451c6d1ddb4787845e2 Mon Sep 17 00:00:00 2001 From: 28JayG Date: Sun, 24 Feb 2019 12:38:43 +0530 Subject: [PATCH 3/9] finishes up cross-fade animation tutorial [with commenting] --- lib/res/home_page.dart | 71 +++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/lib/res/home_page.dart b/lib/res/home_page.dart index 37bc4bc..406f558 100644 --- a/lib/res/home_page.dart +++ b/lib/res/home_page.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; - const Duration duration = Duration( milliseconds: 600, ); @@ -14,29 +13,14 @@ class MyHomePage extends StatefulWidget { } class _MyHomePageState extends State with TickerProviderStateMixin { - double height; - double width; - Color color; - BoxShape boxShape = BoxShape.rectangle; - bool isCircle; - - @override - void initState() { - super.initState(); - height = 100.0; - width = 100.0; - color = Colors.blue; - isCircle = false; - } - - _toggle() { - setState(() { - boxShape = isCircle ? BoxShape.circle : BoxShape.rectangle; - height = isCircle ? 400.0 : 100.0; - width = isCircle ? 400.0 : 100.0; - color = isCircle ? Colors.red : Colors.blue; - }); - } +// bool isFirstVisible; +// +// @override +// void initState() { +// super.initState(); +// +// isFirstVisible = true; +// } @override Widget build(BuildContext context) { @@ -45,21 +29,36 @@ class _MyHomePageState extends State with TickerProviderStateMixin { title: new Text(widget.title), ), body: new Center( - child: AnimatedContainer( - curve: Curves.fastOutSlowIn, - duration: duration, - width: width, - height: height, - decoration: BoxDecoration( - color: color, -// shape: boxShape, - ), - ), +// child: AnimatedCrossFade( +//// layoutBuilder: (Widget firstChild, Key firstChildKey, Widget secondChild, Key secondChildKey,){ +//// +//// return Stack( +//// alignment: Alignment.center, +//// children: [ +//// firstChild, +//// secondChild, +//// ], +//// ); +//// +//// }, +// firstChild: FlutterLogo( +// size: 100.0, +// ), +// secondChild: Container( +// color: Colors.purple, +// height: 200.0, +// width: 150.0, +// ), +// crossFadeState: isFirstVisible +// ? CrossFadeState.showFirst +// : CrossFadeState.showSecond, +// duration: duration, +// ), ), floatingActionButton: new FloatingActionButton( onPressed: () { - isCircle = !isCircle; - _toggle(); +// isFirstVisible = !isFirstVisible; +// setState(() {}); }, tooltip: 'Animate', child: new Icon(Icons.add), From d7792ec8df47227eab7f12f7aa80655cf89c4175 Mon Sep 17 00:00:00 2001 From: 28JayG Date: Sun, 24 Feb 2019 13:50:32 +0530 Subject: [PATCH 4/9] navigator added to a secondary page --- lib/res/home_page.dart | 47 +++++++------------------------------ lib/res/secondary_page.dart | 18 ++++++++++++++ 2 files changed, 27 insertions(+), 38 deletions(-) create mode 100644 lib/res/secondary_page.dart diff --git a/lib/res/home_page.dart b/lib/res/home_page.dart index 406f558..e8aa621 100644 --- a/lib/res/home_page.dart +++ b/lib/res/home_page.dart @@ -1,3 +1,4 @@ +import 'package:animations/res/secondary_page.dart'; import 'package:flutter/material.dart'; const Duration duration = Duration( @@ -13,52 +14,22 @@ class MyHomePage extends StatefulWidget { } class _MyHomePageState extends State with TickerProviderStateMixin { -// bool isFirstVisible; -// -// @override -// void initState() { -// super.initState(); -// -// isFirstVisible = true; -// } - @override Widget build(BuildContext context) { return new Scaffold( appBar: new AppBar( title: new Text(widget.title), ), - body: new Center( -// child: AnimatedCrossFade( -//// layoutBuilder: (Widget firstChild, Key firstChildKey, Widget secondChild, Key secondChildKey,){ -//// -//// return Stack( -//// alignment: Alignment.center, -//// children: [ -//// firstChild, -//// secondChild, -//// ], -//// ); -//// -//// }, -// firstChild: FlutterLogo( -// size: 100.0, -// ), -// secondChild: Container( -// color: Colors.purple, -// height: 200.0, -// width: 150.0, -// ), -// crossFadeState: isFirstVisible -// ? CrossFadeState.showFirst -// : CrossFadeState.showSecond, -// duration: duration, -// ), - ), + body: new Center(), floatingActionButton: new FloatingActionButton( onPressed: () { -// isFirstVisible = !isFirstVisible; -// setState(() {}); + Navigator.of(context).push( + MaterialPageRoute( + builder: (BuildContext context) { + return SecondaryPage(title: 'Secondary Page',); + }, + ), + ); }, tooltip: 'Animate', child: new Icon(Icons.add), diff --git a/lib/res/secondary_page.dart b/lib/res/secondary_page.dart new file mode 100644 index 0000000..fe68904 --- /dev/null +++ b/lib/res/secondary_page.dart @@ -0,0 +1,18 @@ +import 'package:flutter/material.dart'; + + +class SecondaryPage extends StatelessWidget { + SecondaryPage({Key key, this.title}) : super(key: key); + final String title; + + @override + Widget build(BuildContext context) { + return new Scaffold( + appBar: new AppBar( + title: new Text(title), + ), + body: new Center( + ), + ); + } +} From 36f07ebe479688b4a90f1f29c30a41a61943748b Mon Sep 17 00:00:00 2001 From: 28JayG Date: Sun, 24 Feb 2019 14:24:07 +0530 Subject: [PATCH 5/9] hero-animation ready --- lib/res/home_page.dart | 31 +++++++++++++++++++++++++++++-- lib/res/secondary_page.dart | 27 +++++++++++++++++++++++++-- pubspec.yaml | 1 + 3 files changed, 55 insertions(+), 4 deletions(-) diff --git a/lib/res/home_page.dart b/lib/res/home_page.dart index e8aa621..a4b23be 100644 --- a/lib/res/home_page.dart +++ b/lib/res/home_page.dart @@ -1,5 +1,6 @@ import 'package:animations/res/secondary_page.dart'; import 'package:flutter/material.dart'; +import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; const Duration duration = Duration( milliseconds: 600, @@ -20,13 +21,39 @@ class _MyHomePageState extends State with TickerProviderStateMixin { appBar: new AppBar( title: new Text(widget.title), ), - body: new Center(), + body: new Stack( + children: [ + + Align( + alignment: Alignment.topRight, + child: Hero( + tag: 'flutter logo', + child: FlutterLogo( + size: 100.0, + ), + ), + ), + Align( + alignment: Alignment.bottomLeft, + child: Hero( + tag: 'some logo', + child: Icon( + MdiIcons.firebase, + size: 100.0, + color: Colors.yellow, + ), + ), + ), + ], + ), floatingActionButton: new FloatingActionButton( onPressed: () { Navigator.of(context).push( MaterialPageRoute( builder: (BuildContext context) { - return SecondaryPage(title: 'Secondary Page',); + return SecondaryPage( + title: 'Secondary Page', + ); }, ), ); diff --git a/lib/res/secondary_page.dart b/lib/res/secondary_page.dart index fe68904..c52b8bc 100644 --- a/lib/res/secondary_page.dart +++ b/lib/res/secondary_page.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; - +import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; class SecondaryPage extends StatelessWidget { SecondaryPage({Key key, this.title}) : super(key: key); @@ -11,7 +11,30 @@ class SecondaryPage extends StatelessWidget { appBar: new AppBar( title: new Text(title), ), - body: new Center( + body: Stack( + children: [ + + Align( + alignment: Alignment.bottomLeft, + child: Hero( + tag: 'flutter logo', + child: FlutterLogo( + size: 200.0, + ), + ), + ), + Align( + alignment: Alignment.topRight, + child: Hero( + tag: 'some logo', + child: Icon( + MdiIcons.firebase, + size: 200.0, + color: Colors.yellow, + ), + ), + ), + ], ), ); } diff --git a/pubspec.yaml b/pubspec.yaml index 2162312..f26cf78 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -19,6 +19,7 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^0.1.2 + material_design_icons_flutter: any dev_dependencies: flutter_test: From 1b9cd5cdef77bf846a8aa1f4240f28803ae2883a Mon Sep 17 00:00:00 2001 From: 28JayG Date: Sun, 24 Feb 2019 14:26:22 +0530 Subject: [PATCH 6/9] commenting done --- lib/res/home_page.dart | 68 +++++++++++++++--------------- lib/res/secondary_page.dart | 82 ++++++++++++++++++------------------- 2 files changed, 75 insertions(+), 75 deletions(-) diff --git a/lib/res/home_page.dart b/lib/res/home_page.dart index a4b23be..4a433ca 100644 --- a/lib/res/home_page.dart +++ b/lib/res/home_page.dart @@ -21,42 +21,42 @@ class _MyHomePageState extends State with TickerProviderStateMixin { appBar: new AppBar( title: new Text(widget.title), ), - body: new Stack( - children: [ - - Align( - alignment: Alignment.topRight, - child: Hero( - tag: 'flutter logo', - child: FlutterLogo( - size: 100.0, - ), - ), - ), - Align( - alignment: Alignment.bottomLeft, - child: Hero( - tag: 'some logo', - child: Icon( - MdiIcons.firebase, - size: 100.0, - color: Colors.yellow, - ), - ), - ), - ], - ), +// body: new Stack( +// children: [ +// +// Align( +// alignment: Alignment.topRight, +// child: Hero( +// tag: 'flutter logo', +// child: FlutterLogo( +// size: 100.0, +// ), +// ), +// ), +// Align( +// alignment: Alignment.bottomLeft, +// child: Hero( +// tag: 'some logo', +// child: Icon( +// MdiIcons.firebase, +// size: 100.0, +// color: Colors.yellow, +// ), +// ), +// ), +// ], +// ), floatingActionButton: new FloatingActionButton( onPressed: () { - Navigator.of(context).push( - MaterialPageRoute( - builder: (BuildContext context) { - return SecondaryPage( - title: 'Secondary Page', - ); - }, - ), - ); +// Navigator.of(context).push( +// MaterialPageRoute( +// builder: (BuildContext context) { +// return SecondaryPage( +// title: 'Secondary Page', +// ); +// }, +// ), +// ); }, tooltip: 'Animate', child: new Icon(Icons.add), diff --git a/lib/res/secondary_page.dart b/lib/res/secondary_page.dart index c52b8bc..6c572ce 100644 --- a/lib/res/secondary_page.dart +++ b/lib/res/secondary_page.dart @@ -1,41 +1,41 @@ -import 'package:flutter/material.dart'; -import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; - -class SecondaryPage extends StatelessWidget { - SecondaryPage({Key key, this.title}) : super(key: key); - final String title; - - @override - Widget build(BuildContext context) { - return new Scaffold( - appBar: new AppBar( - title: new Text(title), - ), - body: Stack( - children: [ - - Align( - alignment: Alignment.bottomLeft, - child: Hero( - tag: 'flutter logo', - child: FlutterLogo( - size: 200.0, - ), - ), - ), - Align( - alignment: Alignment.topRight, - child: Hero( - tag: 'some logo', - child: Icon( - MdiIcons.firebase, - size: 200.0, - color: Colors.yellow, - ), - ), - ), - ], - ), - ); - } -} +//import 'package:flutter/material.dart'; +//import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; +// +//class SecondaryPage extends StatelessWidget { +// SecondaryPage({Key key, this.title}) : super(key: key); +// final String title; +// +// @override +// Widget build(BuildContext context) { +// return new Scaffold( +// appBar: new AppBar( +// title: new Text(title), +// ), +// body: Stack( +// children: [ +// +// Align( +// alignment: Alignment.bottomLeft, +// child: Hero( +// tag: 'flutter logo', +// child: FlutterLogo( +// size: 200.0, +// ), +// ), +// ), +// Align( +// alignment: Alignment.topRight, +// child: Hero( +// tag: 'some logo', +// child: Icon( +// MdiIcons.firebase, +// size: 200.0, +// color: Colors.yellow, +// ), +// ), +// ), +// ], +// ), +// ); +// } +//} From 4c3e6afb865d0e66582919e48cf446bac7b84111 Mon Sep 17 00:00:00 2001 From: 28JayG Date: Mon, 25 Feb 2019 22:09:31 +0530 Subject: [PATCH 7/9] Adds todo --- lib/res/home_page.dart | 72 ++++++++++++++++---------------- lib/res/secondary_page.dart | 82 ++++++++++++++++++------------------- 2 files changed, 77 insertions(+), 77 deletions(-) diff --git a/lib/res/home_page.dart b/lib/res/home_page.dart index 4a433ca..938478c 100644 --- a/lib/res/home_page.dart +++ b/lib/res/home_page.dart @@ -1,7 +1,7 @@ import 'package:animations/res/secondary_page.dart'; import 'package:flutter/material.dart'; import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; - +//TODO:Add more to hero const Duration duration = Duration( milliseconds: 600, ); @@ -21,45 +21,45 @@ class _MyHomePageState extends State with TickerProviderStateMixin { appBar: new AppBar( title: new Text(widget.title), ), -// body: new Stack( -// children: [ -// -// Align( -// alignment: Alignment.topRight, -// child: Hero( -// tag: 'flutter logo', -// child: FlutterLogo( -// size: 100.0, -// ), -// ), -// ), -// Align( -// alignment: Alignment.bottomLeft, -// child: Hero( -// tag: 'some logo', -// child: Icon( -// MdiIcons.firebase, -// size: 100.0, -// color: Colors.yellow, -// ), -// ), -// ), -// ], -// ), + body: new Stack( + children: [ + + Align( + alignment: Alignment.topRight, + child: Hero( + tag: 'flutter logo', + child: FlutterLogo( + size: 100.0, + ), + ), + ), + Align( + alignment: Alignment.bottomLeft, + child: Hero( + tag: 'some logo', + child: Icon( + MdiIcons.firebase, + size: 100.0, + color: Colors.yellow, + ), + ), + ), + ], + ), floatingActionButton: new FloatingActionButton( onPressed: () { -// Navigator.of(context).push( -// MaterialPageRoute( -// builder: (BuildContext context) { -// return SecondaryPage( -// title: 'Secondary Page', -// ); -// }, -// ), -// ); + Navigator.of(context).push( + MaterialPageRoute( + builder: (BuildContext context) { + return SecondaryPage( + title: 'Secondary Page', + ); + }, + ), + ); }, tooltip: 'Animate', - child: new Icon(Icons.add), + child: new Icon(Icons.add ), ), ); } diff --git a/lib/res/secondary_page.dart b/lib/res/secondary_page.dart index 6c572ce..c52b8bc 100644 --- a/lib/res/secondary_page.dart +++ b/lib/res/secondary_page.dart @@ -1,41 +1,41 @@ -//import 'package:flutter/material.dart'; -//import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; -// -//class SecondaryPage extends StatelessWidget { -// SecondaryPage({Key key, this.title}) : super(key: key); -// final String title; -// -// @override -// Widget build(BuildContext context) { -// return new Scaffold( -// appBar: new AppBar( -// title: new Text(title), -// ), -// body: Stack( -// children: [ -// -// Align( -// alignment: Alignment.bottomLeft, -// child: Hero( -// tag: 'flutter logo', -// child: FlutterLogo( -// size: 200.0, -// ), -// ), -// ), -// Align( -// alignment: Alignment.topRight, -// child: Hero( -// tag: 'some logo', -// child: Icon( -// MdiIcons.firebase, -// size: 200.0, -// color: Colors.yellow, -// ), -// ), -// ), -// ], -// ), -// ); -// } -//} +import 'package:flutter/material.dart'; +import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; + +class SecondaryPage extends StatelessWidget { + SecondaryPage({Key key, this.title}) : super(key: key); + final String title; + + @override + Widget build(BuildContext context) { + return new Scaffold( + appBar: new AppBar( + title: new Text(title), + ), + body: Stack( + children: [ + + Align( + alignment: Alignment.bottomLeft, + child: Hero( + tag: 'flutter logo', + child: FlutterLogo( + size: 200.0, + ), + ), + ), + Align( + alignment: Alignment.topRight, + child: Hero( + tag: 'some logo', + child: Icon( + MdiIcons.firebase, + size: 200.0, + color: Colors.yellow, + ), + ), + ), + ], + ), + ); + } +} From 5cc17049e1328c0dc128dfa628ca703a435c899c Mon Sep 17 00:00:00 2001 From: 28JayG Date: Mon, 25 Feb 2019 23:09:14 +0530 Subject: [PATCH 8/9] boxTransition Over --- lib/res/home_page.dart | 73 ++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/lib/res/home_page.dart b/lib/res/home_page.dart index 938478c..0a1e3f0 100644 --- a/lib/res/home_page.dart +++ b/lib/res/home_page.dart @@ -1,7 +1,7 @@ import 'package:animations/res/secondary_page.dart'; import 'package:flutter/material.dart'; import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; -//TODO:Add more to hero + const Duration duration = Duration( milliseconds: 600, ); @@ -15,51 +15,56 @@ class MyHomePage extends StatefulWidget { } class _MyHomePageState extends State with TickerProviderStateMixin { + Animation animation; + AnimationController controller; + + @override + void initState() { + super.initState(); + + controller = AnimationController(vsync: this, duration: duration) + ..addListener(() => setState(() {})); + animation = DecorationTween( + begin: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(30), + boxShadow: [ + BoxShadow(color: Colors.black54, blurRadius: 30, spreadRadius: 15), + BoxShadow(color: Colors.blue, blurRadius: 15, spreadRadius: 7), + ], + ), + end: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(0.0), + boxShadow: [ + BoxShadow(color: Colors.blue, blurRadius: 15, spreadRadius: 7), + ] + ),) + .animate(controller); + } + @override Widget build(BuildContext context) { return new Scaffold( + backgroundColor: Colors.white, appBar: new AppBar( title: new Text(widget.title), ), - body: new Stack( - children: [ - - Align( - alignment: Alignment.topRight, - child: Hero( - tag: 'flutter logo', - child: FlutterLogo( - size: 100.0, - ), - ), + body: Center( + child: DecoratedBoxTransition( + position: DecorationPosition.background, + decoration: animation, + child: FlutterLogo( + size: 200, ), - Align( - alignment: Alignment.bottomLeft, - child: Hero( - tag: 'some logo', - child: Icon( - MdiIcons.firebase, - size: 100.0, - color: Colors.yellow, - ), - ), - ), - ], + ), ), floatingActionButton: new FloatingActionButton( onPressed: () { - Navigator.of(context).push( - MaterialPageRoute( - builder: (BuildContext context) { - return SecondaryPage( - title: 'Secondary Page', - ); - }, - ), - ); + controller.isCompleted?controller.reverse():controller.forward(); }, tooltip: 'Animate', - child: new Icon(Icons.add ), + child: new Icon(Icons.add), ), ); } From ae49bccf9c4f44584b202cb804cf9fd894bec006 Mon Sep 17 00:00:00 2001 From: 28JayG Date: Mon, 25 Feb 2019 23:35:28 +0530 Subject: [PATCH 9/9] Commenting done --- lib/res/home_page.dart | 76 +++++++++++++++++++------------------ lib/res/secondary_page.dart | 41 -------------------- 2 files changed, 40 insertions(+), 77 deletions(-) delete mode 100644 lib/res/secondary_page.dart diff --git a/lib/res/home_page.dart b/lib/res/home_page.dart index 0a1e3f0..d2dadfe 100644 --- a/lib/res/home_page.dart +++ b/lib/res/home_page.dart @@ -1,6 +1,5 @@ -import 'package:animations/res/secondary_page.dart'; + import 'package:flutter/material.dart'; -import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; const Duration duration = Duration( milliseconds: 600, @@ -15,33 +14,36 @@ class MyHomePage extends StatefulWidget { } class _MyHomePageState extends State with TickerProviderStateMixin { - Animation animation; - AnimationController controller; - @override - void initState() { - super.initState(); + //TODO: [2] Declare and initialize animation and controller + // {Hint: DecoratedBoxTransition will take animation of type Decoration} +// Animation animation; +// AnimationController controller; - controller = AnimationController(vsync: this, duration: duration) - ..addListener(() => setState(() {})); - animation = DecorationTween( - begin: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(30), - boxShadow: [ - BoxShadow(color: Colors.black54, blurRadius: 30, spreadRadius: 15), - BoxShadow(color: Colors.blue, blurRadius: 15, spreadRadius: 7), - ], - ), - end: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(0.0), - boxShadow: [ - BoxShadow(color: Colors.blue, blurRadius: 15, spreadRadius: 7), - ] - ),) - .animate(controller); - } +// @override +// void initState() { +// super.initState(); +// +// controller = AnimationController(vsync: this, duration: duration) +// ..addListener(() => setState(() {})); +// animation = DecorationTween( +// begin: BoxDecoration( +// color: Colors.white, +// borderRadius: BorderRadius.circular(30), +// boxShadow: [ +// BoxShadow(color: Colors.black54, blurRadius: 30, spreadRadius: 15), +// BoxShadow(color: Colors.blue, blurRadius: 15, spreadRadius: 7), +// ], +// ), +// end: BoxDecoration( +// color: Colors.white, +// borderRadius: BorderRadius.circular(0.0), +// boxShadow: [ +// BoxShadow(color: Colors.blue, blurRadius: 15, spreadRadius: 7), +// ] +// ),) +// .animate(controller); +// } @override Widget build(BuildContext context) { @@ -51,20 +53,22 @@ class _MyHomePageState extends State with TickerProviderStateMixin { title: new Text(widget.title), ), body: Center( - child: DecoratedBoxTransition( - position: DecorationPosition.background, - decoration: animation, - child: FlutterLogo( - size: 200, - ), - ), +//TODO:[3] give the DecoratedBoxTransition its decoration and child + //TODO:[1] Bring in the DecoratedBoxTransition +// child: DecoratedBoxTransition( +//// position: DecorationPosition.background, +//// decoration: animation, +//// child: FlutterLogo( +//// size: 200, +//// ), +// ), ), floatingActionButton: new FloatingActionButton( onPressed: () { - controller.isCompleted?controller.reverse():controller.forward(); +// controller.isCompleted?controller.reverse():controller.forward(); }, tooltip: 'Animate', - child: new Icon(Icons.add), + child: new Icon(Icons.play_arrow), ), ); } diff --git a/lib/res/secondary_page.dart b/lib/res/secondary_page.dart deleted file mode 100644 index c52b8bc..0000000 --- a/lib/res/secondary_page.dart +++ /dev/null @@ -1,41 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; - -class SecondaryPage extends StatelessWidget { - SecondaryPage({Key key, this.title}) : super(key: key); - final String title; - - @override - Widget build(BuildContext context) { - return new Scaffold( - appBar: new AppBar( - title: new Text(title), - ), - body: Stack( - children: [ - - Align( - alignment: Alignment.bottomLeft, - child: Hero( - tag: 'flutter logo', - child: FlutterLogo( - size: 200.0, - ), - ), - ), - Align( - alignment: Alignment.topRight, - child: Hero( - tag: 'some logo', - child: Icon( - MdiIcons.firebase, - size: 200.0, - color: Colors.yellow, - ), - ), - ), - ], - ), - ); - } -}