Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animation tutorial: create full example apps and use code excerpter #2320

Merged
merged 10 commits into from
Jan 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions examples/animation/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.DS_Store
pubspec.lock

*/**/android
*/**/ios
*/**/.gitignore
*/**/.metadata
1 change: 1 addition & 0 deletions examples/animation/animate0/README.md
21 changes: 21 additions & 0 deletions examples/animation/animate0/lib/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:flutter/material.dart';

void main() => runApp(LogoApp());

class LogoApp extends StatefulWidget {
_LogoAppState createState() => _LogoAppState();
}

class _LogoAppState extends State<LogoApp> {
@override
Widget build(BuildContext context) {
return Center(
child: Container(
margin: EdgeInsets.symmetric(vertical: 10),
height: 300,
width: 300,
child: FlutterLogo(),
),
);
}
}
19 changes: 19 additions & 0 deletions examples/animation/animate0/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: animation
description: >
Sample app from "Building Layouts", https://flutter.io/docs/development/ui/layout.
version: 1.0.0

environment:
sdk: '>=2.0.0-dev.68.0 <3.0.0'

dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2

dev_dependencies:
flutter_test:
sdk: flutter

flutter:
uses-material-design: true
12 changes: 12 additions & 0 deletions examples/animation/animate0/test/widget_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Basic Flutter widget test. Learn more at https://flutter.io/docs/testing.

import 'package:animation/main.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';

void main() {
testWidgets('Codelab smoke test', (WidgetTester tester) async {
await tester.pumpWidget(new LogoApp());
expect(find.byType(FlutterLogo), findsOneWidget);
});
}
1 change: 1 addition & 0 deletions examples/animation/animate1/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// Copyright 2017 The Chromium Authors. 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/animation.dart';
import 'package:flutter/material.dart';

void main() => runApp(LogoApp());

class LogoApp extends StatefulWidget {
_LogoAppState createState() => _LogoAppState();
}
Expand All @@ -13,36 +11,39 @@ class _LogoAppState extends State<LogoApp> with SingleTickerProviderStateMixin {
Animation<double> animation;
AnimationController controller;

initState() {
@override
void initState() {
super.initState();
controller = AnimationController(
duration: const Duration(milliseconds: 2000), vsync: this);
animation = Tween(begin: 0.0, end: 300.0).animate(controller)
controller =
AnimationController(duration: const Duration(seconds: 2), vsync: this);
// #docregion addListener
animation = Tween<double>(begin: 0, end: 300).animate(controller)
..addListener(() {
// #enddocregion addListener
setState(() {
// the state that has changed here is the animation object’s value
// The state that has changed here is the animation object’s value.
});
// #docregion addListener
});
// #enddocregion addListener
controller.forward();
}

@override
Widget build(BuildContext context) {
return Center(
child: Container(
margin: EdgeInsets.symmetric(vertical: 10.0),
margin: EdgeInsets.symmetric(vertical: 10),
height: animation.value,
width: animation.value,
child: FlutterLogo(),
),
);
}

dispose() {
@override
void dispose() {
controller.dispose();
super.dispose();
}
}

void main() {
runApp(LogoApp());
}
19 changes: 19 additions & 0 deletions examples/animation/animate1/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: animation
description: >
Sample app from "Building Layouts", https://flutter.io/docs/development/ui/layout.
version: 1.0.0

environment:
sdk: '>=2.0.0-dev.68.0 <3.0.0'

dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2

dev_dependencies:
flutter_test:
sdk: flutter

flutter:
uses-material-design: true
12 changes: 12 additions & 0 deletions examples/animation/animate1/test/widget_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Basic Flutter widget test. Learn more at https://flutter.io/docs/testing.

import 'package:animation/main.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';

void main() {
testWidgets('Codelab smoke test', (WidgetTester tester) async {
await tester.pumpWidget(new LogoApp());
expect(find.byType(FlutterLogo), findsOneWidget);
});
}
1 change: 1 addition & 0 deletions examples/animation/animate2/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Demonstrates a simple animation with AnimatedWidget.

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

void main() => runApp(LogoApp());

// #docregion AnimatedLogo
class AnimatedLogo extends AnimatedWidget {
AnimatedLogo({Key key, Animation<double> animation})
: super(key: key, listenable: animation);
Expand All @@ -15,41 +12,39 @@ class AnimatedLogo extends AnimatedWidget {
final Animation<double> animation = listenable;
return Center(
child: Container(
margin: EdgeInsets.symmetric(vertical: 10.0),
margin: EdgeInsets.symmetric(vertical: 10),
height: animation.value,
width: animation.value,
child: FlutterLogo(),
),
);
}
}
// #enddocregion AnimatedLogo

class LogoApp extends StatefulWidget {
_LogoAppState createState() => _LogoAppState();
}

class _LogoAppState extends State<LogoApp> with SingleTickerProviderStateMixin {
AnimationController controller;
Animation<double> animation;
AnimationController controller;

initState() {
@override
void initState() {
super.initState();
controller = AnimationController(
duration: const Duration(milliseconds: 2000), vsync: this);
animation = Tween(begin: 0.0, end: 300.0).animate(controller);
controller =
AnimationController(duration: const Duration(seconds: 2), vsync: this);
animation = Tween<double>(begin: 0, end: 300).animate(controller);
controller.forward();
}

Widget build(BuildContext context) {
return AnimatedLogo(animation: animation);
}
@override
Widget build(BuildContext context) => AnimatedLogo(animation: animation);

dispose() {
@override
void dispose() {
controller.dispose();
super.dispose();
}
}

void main() {
runApp(LogoApp());
}
19 changes: 19 additions & 0 deletions examples/animation/animate2/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: animation
description: >
Sample app from "Building Layouts", https://flutter.io/docs/development/ui/layout.
version: 1.0.0

environment:
sdk: '>=2.0.0-dev.68.0 <3.0.0'

dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2

dev_dependencies:
flutter_test:
sdk: flutter

flutter:
uses-material-design: true
12 changes: 12 additions & 0 deletions examples/animation/animate2/test/widget_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Basic Flutter widget test. Learn more at https://flutter.io/docs/testing.

import 'package:animation/main.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';

void main() {
testWidgets('Codelab smoke test', (WidgetTester tester) async {
await tester.pumpWidget(new LogoApp());
expect(find.byType(FlutterLogo), findsOneWidget);
});
}
1 change: 1 addition & 0 deletions examples/animation/animate3/README.md
61 changes: 61 additions & 0 deletions examples/animation/animate3/lib/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import 'package:flutter/animation.dart';
import 'package:flutter/material.dart';

void main() => runApp(LogoApp());

class AnimatedLogo extends AnimatedWidget {
AnimatedLogo({Key key, Animation<double> animation})
: super(key: key, listenable: animation);

Widget build(BuildContext context) {
final Animation<double> animation = listenable;
return Center(
child: Container(
margin: EdgeInsets.symmetric(vertical: 10),
height: animation.value,
width: animation.value,
child: FlutterLogo(),
),
);
}
}

class LogoApp extends StatefulWidget {
_LogoAppState createState() => _LogoAppState();
}

// #docregion print-state
class _LogoAppState extends State<LogoApp> with SingleTickerProviderStateMixin {
Animation<double> animation;
AnimationController controller;

@override
void initState() {
super.initState();
controller =
AnimationController(duration: const Duration(seconds: 2), vsync: this);
animation = Tween<double>(begin: 0, end: 300).animate(controller)
// #enddocregion print-state
..addStatusListener((status) {
if (status == AnimationStatus.completed) {
controller.reverse();
} else if (status == AnimationStatus.dismissed) {
controller.forward();
}
})
// #docregion print-state
..addStatusListener((state) => print('$state'));
controller.forward();
}
// #enddocregion print-state

@override
Widget build(BuildContext context) => AnimatedLogo(animation: animation);

@override
void dispose() {
controller.dispose();
super.dispose();
}
// #docregion print-state
}
19 changes: 19 additions & 0 deletions examples/animation/animate3/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: animation
description: >
Sample app from "Building Layouts", https://flutter.io/docs/development/ui/layout.
version: 1.0.0

environment:
sdk: '>=2.0.0-dev.68.0 <3.0.0'

dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2

dev_dependencies:
flutter_test:
sdk: flutter

flutter:
uses-material-design: true
12 changes: 12 additions & 0 deletions examples/animation/animate3/test/widget_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Basic Flutter widget test. Learn more at https://flutter.io/docs/testing.

import 'package:animation/main.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';

void main() {
testWidgets('Codelab smoke test', (WidgetTester tester) async {
await tester.pumpWidget(new LogoApp());
expect(find.byType(FlutterLogo), findsOneWidget);
});
}
1 change: 1 addition & 0 deletions examples/animation/animate4/README.md
Loading