Skip to content

Commit

Permalink
add AnimatedBuilder demo
Browse files Browse the repository at this point in the history
  • Loading branch information
X-Wei committed Jul 21, 2019
1 parent 2d4e702 commit 090a0f3
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/my_app_meta.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:provider/provider.dart';
import './my_route.dart';
import './routes/about.dart';

import './routes/animation_animated_builder_ex.dart';
import './routes/animation_animated_widget_ex.dart';
import './routes/animation_basic_ex.dart';
import './routes/animation_hero_ex.dart';
Expand Down Expand Up @@ -175,6 +176,7 @@ const kMyAppRoutesStructure = <MyRouteGroup>[
HeroExample(),
BasicAnimationExample(),
AnimatedWidgetExample(),
AnimatedBuilderExample(),
],
),
MyRouteGroup(
Expand Down
79 changes: 79 additions & 0 deletions lib/routes/animation_animated_builder_ex.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import 'dart:math';

import 'package:flutter/material.dart';
import '../my_route.dart';

class AnimatedBuilderExample extends MyRoute {
const AnimatedBuilderExample(
[String sourceFile = 'lib/routes/animation_animated_builder_ex.dart'])
: super(sourceFile);

@override
get title => 'AnimatedBuilder';

@override
get description => 'Similar to AnimatedWidget.';

@override
get links => {
'Tutorial':
'https://flutter.dev/docs/development/ui/animations/tutorial#refactoring-with-animatedbuilder',
'Widget of the Week (YouTube)': 'https://youtu.be/N-RiyZlv8v8',
};

@override
Widget buildMyRouteContent(BuildContext context) {
return new _AnimatedBuilderDemo();
}
}

class _AnimatedBuilderDemo extends StatefulWidget {
@override
_AnimatedBuilderDemoState createState() => _AnimatedBuilderDemoState();
}

class _AnimatedBuilderDemoState extends State<_AnimatedBuilderDemo>
with SingleTickerProviderStateMixin {
AnimationController _controller;

@override
void initState() {
super.initState();
this._controller =
AnimationController(duration: Duration(seconds: 1), vsync: this);
}

@override
void dispose() {
super.dispose();
this._controller.dispose();
}

@override
Widget build(BuildContext context) {
final rotateAnimation =
Tween<double>(begin: 0, end: pi).animate(this._controller);
return Column(
children: <Widget>[
AnimatedBuilder(
animation: rotateAnimation,
child: FlutterLogo(size: 72.0),
builder: (context, child) {
return Transform.rotate(
angle: rotateAnimation.value,
child: child,
);
},
),
RaisedButton(
child: Text('Forward animation'),
onPressed: () => _controller.forward(),
),
RaisedButton(
child: Text('Reverse animation'),
onPressed: () => _controller.reverse(),
),
],
);
}
}

0 comments on commit 090a0f3

Please sign in to comment.