1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-09 14:28:51 +00:00
Files
samples/animations/lib/src/basics/04_tweens.dart
John Ryan 349ca7bc6f 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
2019-08-13 14:13:57 -07:00

68 lines
1.9 KiB
Dart

// 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 {
static const String routeName = '/basics/tweens';
_TweenDemoState createState() => _TweenDemoState();
}
class _TweenDemoState extends State<TweenDemo>
with SingleTickerProviderStateMixin {
static const Duration _duration = Duration(seconds: 1);
static const double accountBalance = 1000000;
AnimationController controller;
Animation<double> animation;
void initState() {
super.initState();
controller = AnimationController(vsync: this, duration: _duration)
..addListener(() {
// Marks the widget tree as dirty
setState(() {});
});
animation = Tween(begin: 0.0, end: accountBalance).animate(controller);
}
void dispose() {
controller.dispose();
super.dispose();
}
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ConstrainedBox(
constraints: BoxConstraints(maxWidth: 200),
child: Text('\$${animation.value.toStringAsFixed(2)}',
style: TextStyle(fontSize: 24)),
),
RaisedButton(
child: Text(
controller.status == AnimationStatus.completed
? 'Buy a Mansion'
: 'Win Lottery',
),
onPressed: () {
if (controller.status == AnimationStatus.completed) {
controller.reverse();
} else {
controller.forward();
}
},
)
],
),
),
);
}
}