add TweenSequence sample (#127)

* Add TweenSequence sample

* rename to TweenSequenceDemo

* add copyright headers

* remote type

* introduce animated builder earlier in basics/

so that other examples can use it

* formatting

* use async / await, increase animation duration
pull/128/head
John Ryan 5 years ago committed by GitHub
parent c2f50f31ff
commit 349ca7bc6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -8,8 +8,9 @@ import 'src/basics/01_animated_container.dart';
import 'src/basics/02_page_route_builder.dart';
import 'src/basics/03_animation_controller.dart';
import 'src/basics/04_tweens.dart';
import 'src/basics/05_custom_tween.dart';
import 'src/basics/06_animated_builder.dart';
import 'src/basics/05_animated_builder.dart';
import 'src/basics/06_custom_tween.dart';
import 'src/basics/07_tween_sequence.dart';
import 'src/misc/card_swipe.dart';
import 'src/misc/carousel.dart';
import 'src/misc/expand_card.dart';
@ -35,10 +36,12 @@ final basicDemos = [
Demo('Animation Controller', AnimationControllerDemo.routeName,
(context) => AnimationControllerDemo()),
Demo('Tweens', TweenDemo.routeName, (context) => TweenDemo()),
Demo('Custom Tween', CustomTweenDemo.routeName,
(context) => CustomTweenDemo()),
Demo('AnimatedBuilder', AnimatedBuilderDemo.routeName,
(context) => AnimatedBuilderDemo()),
Demo('Custom Tween', CustomTweenDemo.routeName,
(context) => CustomTweenDemo()),
Demo('Tween Sequences', TweenSequenceDemo.routeName,
(context) => TweenSequenceDemo()),
];
final miscDemos = [

@ -1,3 +1,7 @@
// Copyright 2019 The Flutter team. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:math';
import 'package:flutter/material.dart';

@ -1,3 +1,7 @@
// Copyright 2019 The Flutter team. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
class PageRouteBuilderDemo extends StatelessWidget {

@ -1,3 +1,7 @@
// Copyright 2019 The Flutter team. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
class TweenDemo extends StatefulWidget {

@ -1,3 +1,7 @@
// Copyright 2019 The Flutter team. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
class AnimatedBuilderDemo extends StatefulWidget {
@ -32,7 +36,7 @@ class _AnimatedBuilderDemoState extends State<AnimatedBuilderDemo>
appBar: AppBar(),
body: Center(
child: AnimatedBuilder(
animation: this.animation,
animation: animation,
builder: (context, child) {
return MaterialButton(
color: animation.value,

@ -1,3 +1,7 @@
// Copyright 2019 The Flutter team. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
class TypewriterTween extends Tween<String> {
@ -26,11 +30,7 @@ class _CustomTweenDemoState extends State<CustomTweenDemo>
void initState() {
super.initState();
controller = AnimationController(vsync: this, duration: _duration)
..addListener(() {
// Marks the widget tree as dirty
setState(() {});
});
controller = AnimationController(vsync: this, duration: _duration);
animation = TypewriterTween(end: message).animate(controller);
}
@ -70,9 +70,14 @@ class _CustomTweenDemoState extends State<CustomTweenDemo>
child: Card(
child: Container(
padding: EdgeInsets.all(8.0),
child: Text('${animation.value}',
style:
TextStyle(fontSize: 16, fontFamily: 'SpecialElite')),
child: AnimatedBuilder(
animation: animation,
builder: (context, child) {
return Text('${animation.value}',
style: TextStyle(
fontSize: 16, fontFamily: 'SpecialElite'));
},
),
),
),
),

@ -0,0 +1,74 @@
// Copyright 2019 The Flutter team. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
class TweenSequenceDemo extends StatefulWidget {
static const String routeName = '/basics/chaining_tweens';
@override
_TweenSequenceDemoState createState() => _TweenSequenceDemoState();
}
class _TweenSequenceDemoState extends State<TweenSequenceDemo>
with SingleTickerProviderStateMixin {
static const Duration duration = Duration(seconds: 3);
AnimationController controller;
Animation<Color> animation;
static final colors = [
Colors.red,
Colors.orange,
Colors.yellow,
Colors.green,
Colors.blue,
Colors.indigo,
Colors.purple,
];
void initState() {
super.initState();
final sequenceItems = <TweenSequenceItem<Color>>[];
for (var i = 0; i < colors.length; i++) {
final beginColor = colors[i];
final endColor = colors[(i + 1) % colors.length];
final weight = 1 / colors.length;
sequenceItems.add(
TweenSequenceItem<Color>(
tween: ColorTween(begin: beginColor, end: endColor),
weight: weight,
),
);
}
controller = AnimationController(duration: duration, vsync: this);
animation = TweenSequence<Color>(sequenceItems).animate(controller);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Center(
child: AnimatedBuilder(
animation: animation,
builder: (context, child) {
return MaterialButton(
color: animation.value,
onPressed: () async {
await controller.forward();
controller.reset();
},
child: child,
);
},
child: Text('Animate', style: TextStyle(color: Colors.white)),
),
),
);
}
}
Loading…
Cancel
Save