mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 22:09:06 +00:00
Add animation samples (#118)
* initialize animations sample project
* add two demos, set up routing
* clean up expand_card demo
* update README
* clean up expand_card demo
* dartfmt
* update comment
* address code review comments
* swap AnimatedContainer and AnimatedCrossFade
* use AnimatedSwitcher instead of AnimatedCrossFade
* Revert "use AnimatedSwitcher instead of AnimatedCrossFade"
This reverts commit e112e02549.
* rename expanded -> selected
* use Dart 2.4.0 constraint
* update README
* address code review comments
update images
add curves to expand_card
update pubspec.lock
* add @override annotation
* add animations project to travis script
* add empty test for travis
* add copyright notice to animations/ project
This commit is contained in:
85
animations/lib/main.dart
Normal file
85
animations/lib/main.dart
Normal file
@@ -0,0 +1,85 @@
|
||||
// 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';
|
||||
import 'src/basics/animation_controller_demo.dart';
|
||||
import 'src/misc/expand_card.dart';
|
||||
|
||||
void main() => runApp(AnimationSamples());
|
||||
|
||||
class Demo {
|
||||
final String name;
|
||||
final String route;
|
||||
final WidgetBuilder builder;
|
||||
|
||||
const Demo(this.name, this.route, this.builder);
|
||||
}
|
||||
|
||||
final basicDemos = [
|
||||
Demo('Animation Controller', AnimationControllerDemo.routeName,
|
||||
(context) => AnimationControllerDemo()),
|
||||
];
|
||||
|
||||
final miscDemos = [
|
||||
Demo('Expandable Card', ExpandCardDemo.routeName,
|
||||
(context) => ExpandCardDemo()),
|
||||
];
|
||||
|
||||
final basicDemoRoutes =
|
||||
Map.fromEntries(basicDemos.map((d) => MapEntry(d.route, d.builder)));
|
||||
|
||||
final miscDemoRoutes =
|
||||
Map.fromEntries(miscDemos.map((d) => MapEntry(d.route, d.builder)));
|
||||
|
||||
final allRoutes = <String, WidgetBuilder>{
|
||||
...basicDemoRoutes,
|
||||
...miscDemoRoutes,
|
||||
};
|
||||
|
||||
class AnimationSamples extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Animation Samples',
|
||||
theme: ThemeData(
|
||||
primarySwatch: Colors.deepPurple,
|
||||
),
|
||||
routes: allRoutes,
|
||||
home: HomePage(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class HomePage extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final headerStyle = Theme.of(context).textTheme.title;
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Animation Samples'),
|
||||
),
|
||||
body: ListView(
|
||||
children: [
|
||||
ListTile(title: Text('Basics', style: headerStyle)),
|
||||
...basicDemos.map((d) => DemoTile(d)),
|
||||
ListTile(title: Text('Misc', style: headerStyle)),
|
||||
...miscDemos.map((d) => DemoTile(d)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class DemoTile extends StatelessWidget {
|
||||
final Demo demo;
|
||||
|
||||
DemoTile(this.demo);
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
title: Text(demo.name),
|
||||
onTap: () {
|
||||
Navigator.pushNamed(context, demo.route);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user