Created
November 2, 2018 10:12
-
-
Save Rahiche/f4e52531c43bb158562010b47d933019 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
class AnimatedIconExample extends StatefulWidget { | |
@override | |
_AnimatedIconExampleState createState() => _AnimatedIconExampleState(); | |
} | |
class _AnimatedIconExampleState extends State<AnimatedIconExample> | |
with SingleTickerProviderStateMixin { | |
PageController pageController = PageController(); | |
AnimationController controller; | |
@override | |
void initState() { | |
super.initState(); | |
controller = | |
AnimationController(vsync: this, duration: Duration(seconds: 1)); | |
} | |
@override | |
void dispose() { | |
controller?.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
leading: GestureDetector( | |
child: Center( | |
child: AnimatedIcon( | |
icon: AnimatedIcons.menu_close, progress: controller), | |
), | |
onTap: () { | |
controller.reverse(); | |
pageController.animateToPage(0, | |
duration: Duration(seconds: 1), curve: Curves.linear); | |
}, | |
), | |
title: Text("Animated Icon Example")), | |
body: PageView( | |
controller: pageController, | |
scrollDirection: Axis.vertical, | |
children: <Widget>[ | |
buildPage0(), | |
Container(color: Colors.green), | |
Container(color: Colors.blue), | |
Container(color: Colors.yellow), | |
Container(color: Colors.pink), | |
], | |
), | |
); | |
} | |
show(int page) { | |
controller.forward(); | |
pageController.animateToPage(page, | |
duration: Duration(seconds: 1), curve: Curves.linear); | |
} | |
Container buildPage0() { | |
return Container( | |
color: Colors.white, | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
ListTile(onTap: () => show(1), title: Center(child: Text("Green"))), | |
ListTile(onTap: () => show(2), title: Center(child: Text("Blue"))), | |
ListTile(onTap: () => show(3), title: Center(child: Text("Yellow"))), | |
ListTile(onTap: () => show(4), title: Center(child: Text("Pink"))), | |
], | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment