mirror of
https://github.com/flutter/samples.git
synced 2026-04-07 12:14:27 +00:00
add animations basics 1-6 (#120)
* add basics * web: update dependencies * TransferableTypeData added (#116) * Updating index with new samples (#121) * use arrow functions * remove newline * use verbs: random*() -> generate*() * remove <Widget>[] type annotation on lists * use raised button * _route() => _createRoute() * add parameter names to pageBuilder * use the text theme's display1 for large text * dispose animation controllers before calling super() * remove local var * use raised buttons instead of material buttons * web: updated dependencies * Added new test scripts (#122) * add carousel, card_swipe, and focus_image samples (#119) * add carousel, card_swipe, and focus_image samples * fix image assets * fix more asset images * add repeating animation * fix import * add copyright headers * remove Center widget * imageAssetName * use ClipRect, refactor _SwipeableCardState * use offset.zero * add comments * remove reference to coverflow package * change spread to toList() * refactor coverflow sample don't set width and height use const data -> images * return widget directly, fix formatting * inline transitionsBuilder * image -> imageAssetName * _rectTween() => _createTween() * _expandToPageRoute -> _createRoute * move non-updating widgets out of AnimatedBuilder * code review updates to animations demos
This commit is contained in:
67
animations/lib/src/basics/03_animation_controller.dart
Normal file
67
animations/lib/src/basics/03_animation_controller.dart
Normal file
@@ -0,0 +1,67 @@
|
||||
// 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 AnimationControllerDemo extends StatefulWidget {
|
||||
static const String routeName = '/basics/animation_controller';
|
||||
|
||||
@override
|
||||
_AnimationControllerDemoState createState() =>
|
||||
_AnimationControllerDemoState();
|
||||
}
|
||||
|
||||
class _AnimationControllerDemoState extends State<AnimationControllerDemo>
|
||||
with SingleTickerProviderStateMixin {
|
||||
static const Duration _duration = Duration(seconds: 1);
|
||||
AnimationController controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
controller = AnimationController(vsync: this, duration: _duration)
|
||||
..addListener(() {
|
||||
// Force build() to be called again
|
||||
setState(() {});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(),
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: 200),
|
||||
child: Text(
|
||||
'${controller.value.toStringAsFixed(2)}',
|
||||
style: Theme.of(context).textTheme.display3,
|
||||
),
|
||||
),
|
||||
RaisedButton(
|
||||
child: Text('animate'),
|
||||
onPressed: () {
|
||||
if (controller.status == AnimationStatus.completed) {
|
||||
controller.reverse();
|
||||
} else {
|
||||
controller.forward();
|
||||
}
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user