Adjust animations lint rules (#814)

pull/833/head
Brett Morgan 3 years ago committed by GitHub
parent 12ba3b2245
commit b1a49c0afb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -12,10 +12,10 @@ linter:
cancel_subscriptions: true cancel_subscriptions: true
close_sinks: true close_sinks: true
directives_ordering: true directives_ordering: true
# Required because of the numbered sources in lib/src/basics
file_names: false file_names: false
package_api_docs: true package_api_docs: true
package_prefixed_library_names: true package_prefixed_library_names: true
test_types_in_equals: true test_types_in_equals: true
throw_in_finally: true throw_in_finally: true
unnecessary_statements: true unnecessary_statements: true
use_key_in_widget_constructors: false

@ -24,7 +24,7 @@ import 'src/misc/hero_animation.dart';
import 'src/misc/physics_card_drag.dart'; import 'src/misc/physics_card_drag.dart';
import 'src/misc/repeating_animation.dart'; import 'src/misc/repeating_animation.dart';
void main() => runApp(AnimationSamples()); void main() => runApp(const AnimationSamples());
class Demo { class Demo {
final String name; final String name;
@ -42,42 +42,42 @@ final basicDemos = [
Demo( Demo(
name: 'AnimatedContainer', name: 'AnimatedContainer',
route: AnimatedContainerDemo.routeName, route: AnimatedContainerDemo.routeName,
builder: (context) => AnimatedContainerDemo()), builder: (context) => const AnimatedContainerDemo()),
Demo( Demo(
name: 'PageRouteBuilder', name: 'PageRouteBuilder',
route: PageRouteBuilderDemo.routeName, route: PageRouteBuilderDemo.routeName,
builder: (context) => PageRouteBuilderDemo()), builder: (context) => const PageRouteBuilderDemo()),
Demo( Demo(
name: 'Animation Controller', name: 'Animation Controller',
route: AnimationControllerDemo.routeName, route: AnimationControllerDemo.routeName,
builder: (context) => AnimationControllerDemo()), builder: (context) => const AnimationControllerDemo()),
Demo( Demo(
name: 'Tweens', name: 'Tweens',
route: TweenDemo.routeName, route: TweenDemo.routeName,
builder: (context) => TweenDemo()), builder: (context) => const TweenDemo()),
Demo( Demo(
name: 'AnimatedBuilder', name: 'AnimatedBuilder',
route: AnimatedBuilderDemo.routeName, route: AnimatedBuilderDemo.routeName,
builder: (context) => AnimatedBuilderDemo()), builder: (context) => const AnimatedBuilderDemo()),
Demo( Demo(
name: 'Custom Tween', name: 'Custom Tween',
route: CustomTweenDemo.routeName, route: CustomTweenDemo.routeName,
builder: (context) => CustomTweenDemo()), builder: (context) => const CustomTweenDemo()),
Demo( Demo(
name: 'Tween Sequences', name: 'Tween Sequences',
route: TweenSequenceDemo.routeName, route: TweenSequenceDemo.routeName,
builder: (context) => TweenSequenceDemo()), builder: (context) => const TweenSequenceDemo()),
Demo( Demo(
name: 'Fade Transition', name: 'Fade Transition',
route: FadeTransitionDemo.routeName, route: FadeTransitionDemo.routeName,
builder: (context) => FadeTransitionDemo()), builder: (context) => const FadeTransitionDemo()),
]; ];
final miscDemos = [ final miscDemos = [
Demo( Demo(
name: 'Expandable Card', name: 'Expandable Card',
route: ExpandCardDemo.routeName, route: ExpandCardDemo.routeName,
builder: (context) => ExpandCardDemo()), builder: (context) => const ExpandCardDemo()),
Demo( Demo(
name: 'Carousel', name: 'Carousel',
route: CarouselDemo.routeName, route: CarouselDemo.routeName,
@ -85,39 +85,39 @@ final miscDemos = [
Demo( Demo(
name: 'Focus Image', name: 'Focus Image',
route: FocusImageDemo.routeName, route: FocusImageDemo.routeName,
builder: (context) => FocusImageDemo()), builder: (context) => const FocusImageDemo()),
Demo( Demo(
name: 'Card Swipe', name: 'Card Swipe',
route: CardSwipeDemo.routeName, route: CardSwipeDemo.routeName,
builder: (context) => CardSwipeDemo()), builder: (context) => const CardSwipeDemo()),
Demo( Demo(
name: 'Repeating Animation', name: 'Repeating Animation',
route: RepeatingAnimationDemo.routeName, route: RepeatingAnimationDemo.routeName,
builder: (context) => RepeatingAnimationDemo()), builder: (context) => const RepeatingAnimationDemo()),
Demo( Demo(
name: 'Spring Physics', name: 'Spring Physics',
route: PhysicsCardDragDemo.routeName, route: PhysicsCardDragDemo.routeName,
builder: (context) => PhysicsCardDragDemo()), builder: (context) => const PhysicsCardDragDemo()),
Demo( Demo(
name: 'AnimatedList', name: 'AnimatedList',
route: AnimatedListDemo.routeName, route: AnimatedListDemo.routeName,
builder: (context) => AnimatedListDemo()), builder: (context) => const AnimatedListDemo()),
Demo( Demo(
name: 'AnimatedPositioned', name: 'AnimatedPositioned',
route: AnimatedPositionedDemo.routeName, route: AnimatedPositionedDemo.routeName,
builder: (context) => AnimatedPositionedDemo()), builder: (context) => const AnimatedPositionedDemo()),
Demo( Demo(
name: 'AnimatedSwitcher', name: 'AnimatedSwitcher',
route: AnimatedSwitcherDemo.routeName, route: AnimatedSwitcherDemo.routeName,
builder: (context) => AnimatedSwitcherDemo()), builder: (context) => const AnimatedSwitcherDemo()),
Demo( Demo(
name: 'Hero Animation', name: 'Hero Animation',
route: HeroAnimationDemo.routeName, route: HeroAnimationDemo.routeName,
builder: (context) => HeroAnimationDemo()), builder: (context) => const HeroAnimationDemo()),
Demo( Demo(
name: 'Curved Animation', name: 'Curved Animation',
route: CurvedAnimationDemo.routeName, route: CurvedAnimationDemo.routeName,
builder: (context) => CurvedAnimationDemo()), builder: (context) => const CurvedAnimationDemo()),
]; ];
final basicDemoRoutes = final basicDemoRoutes =
@ -132,6 +132,8 @@ final allRoutes = <String, WidgetBuilder>{
}; };
class AnimationSamples extends StatelessWidget { class AnimationSamples extends StatelessWidget {
const AnimationSamples({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp(
@ -140,12 +142,14 @@ class AnimationSamples extends StatelessWidget {
primarySwatch: Colors.deepPurple, primarySwatch: Colors.deepPurple,
), ),
routes: allRoutes, routes: allRoutes,
home: HomePage(), home: const HomePage(),
); );
} }
} }
class HomePage extends StatelessWidget { class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final headerStyle = Theme.of(context).textTheme.headline6; final headerStyle = Theme.of(context).textTheme.headline6;
@ -156,9 +160,9 @@ class HomePage extends StatelessWidget {
body: ListView( body: ListView(
children: [ children: [
ListTile(title: Text('Basics', style: headerStyle)), ListTile(title: Text('Basics', style: headerStyle)),
...basicDemos.map((d) => DemoTile(d)), ...basicDemos.map((d) => DemoTile(demo: d)),
ListTile(title: Text('Misc', style: headerStyle)), ListTile(title: Text('Misc', style: headerStyle)),
...miscDemos.map((d) => DemoTile(d)), ...miscDemos.map((d) => DemoTile(demo: d)),
], ],
), ),
); );
@ -168,7 +172,7 @@ class HomePage extends StatelessWidget {
class DemoTile extends StatelessWidget { class DemoTile extends StatelessWidget {
final Demo demo; final Demo demo;
const DemoTile(this.demo); const DemoTile({required this.demo, Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

@ -11,6 +11,7 @@ double generateMargin() => Random().nextDouble() * 64;
Color generateColor() => Color(0xFFFFFFFF & Random().nextInt(0xFFFFFFFF)); Color generateColor() => Color(0xFFFFFFFF & Random().nextInt(0xFFFFFFFF));
class AnimatedContainerDemo extends StatefulWidget { class AnimatedContainerDemo extends StatefulWidget {
const AnimatedContainerDemo({Key? key}) : super(key: key);
static String routeName = '/basics/01_animated_container'; static String routeName = '/basics/01_animated_container';
@override @override

@ -5,6 +5,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class PageRouteBuilderDemo extends StatelessWidget { class PageRouteBuilderDemo extends StatelessWidget {
const PageRouteBuilderDemo({Key? key}) : super(key: key);
static const String routeName = '/basics/page_route_builder'; static const String routeName = '/basics/page_route_builder';
@override @override

@ -5,6 +5,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class AnimationControllerDemo extends StatefulWidget { class AnimationControllerDemo extends StatefulWidget {
const AnimationControllerDemo({Key? key}) : super(key: key);
static const String routeName = '/basics/animation_controller'; static const String routeName = '/basics/animation_controller';
@override @override

@ -5,6 +5,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class TweenDemo extends StatefulWidget { class TweenDemo extends StatefulWidget {
const TweenDemo({Key? key}) : super(key: key);
static const String routeName = '/basics/tweens'; static const String routeName = '/basics/tweens';
@override @override

@ -5,6 +5,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class AnimatedBuilderDemo extends StatefulWidget { class AnimatedBuilderDemo extends StatefulWidget {
const AnimatedBuilderDemo({Key? key}) : super(key: key);
static const String routeName = '/basics/animated_builder'; static const String routeName = '/basics/animated_builder';
@override @override

@ -16,6 +16,7 @@ class TypewriterTween extends Tween<String> {
} }
class CustomTweenDemo extends StatefulWidget { class CustomTweenDemo extends StatefulWidget {
const CustomTweenDemo({Key? key}) : super(key: key);
static const String routeName = '/basics/custom_tweens'; static const String routeName = '/basics/custom_tweens';
@override @override

@ -5,6 +5,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class TweenSequenceDemo extends StatefulWidget { class TweenSequenceDemo extends StatefulWidget {
const TweenSequenceDemo({Key? key}) : super(key: key);
static const String routeName = '/basics/chaining_tweens'; static const String routeName = '/basics/chaining_tweens';
@override @override

@ -7,6 +7,7 @@ import 'package:flutter/material.dart';
// Refer to the AnimatedWidget docs here - https://api.flutter.dev/flutter/widgets/AnimatedWidget-class.html // Refer to the AnimatedWidget docs here - https://api.flutter.dev/flutter/widgets/AnimatedWidget-class.html
// for examples of other common animated widgets. // for examples of other common animated widgets.
class FadeTransitionDemo extends StatefulWidget { class FadeTransitionDemo extends StatefulWidget {
const FadeTransitionDemo({Key? key}) : super(key: key);
static const String routeName = '/basics/fade_transition'; static const String routeName = '/basics/fade_transition';
@override @override

@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
class AnimatedListDemo extends StatefulWidget { class AnimatedListDemo extends StatefulWidget {
const AnimatedListDemo({Key? key}) : super(key: key);
static String routeName = '/misc/animated_list'; static String routeName = '/misc/animated_list';
@override @override

@ -7,6 +7,7 @@ import 'dart:math';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class AnimatedPositionedDemo extends StatefulWidget { class AnimatedPositionedDemo extends StatefulWidget {
const AnimatedPositionedDemo({Key? key}) : super(key: key);
static String routeName = '/basics/09_animated_positioned'; static String routeName = '/basics/09_animated_positioned';
@override @override

@ -23,6 +23,7 @@ Widget generateContainer(int keyCount) => Container(
); );
class AnimatedSwitcherDemo extends StatefulWidget { class AnimatedSwitcherDemo extends StatefulWidget {
const AnimatedSwitcherDemo({Key? key}) : super(key: key);
static String routeName = '/basics/10_animated_switcher'; static String routeName = '/basics/10_animated_switcher';
@override @override

@ -8,6 +8,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/physics.dart'; import 'package:flutter/physics.dart';
class CardSwipeDemo extends StatefulWidget { class CardSwipeDemo extends StatefulWidget {
const CardSwipeDemo({Key? key}) : super(key: key);
static String routeName = '/misc/card_swipe'; static String routeName = '/misc/card_swipe';
@override @override
@ -78,7 +79,7 @@ class _CardSwipeDemoState extends State<CardSwipeDemo> {
class Card extends StatelessWidget { class Card extends StatelessWidget {
final String imageAssetName; final String imageAssetName;
const Card(this.imageAssetName); const Card({required this.imageAssetName, Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -101,10 +102,9 @@ class SwipeableCard extends StatefulWidget {
final String imageAssetName; final String imageAssetName;
final VoidCallback onSwiped; final VoidCallback onSwiped;
const SwipeableCard({ const SwipeableCard(
required this.onSwiped, {required this.onSwiped, required this.imageAssetName, Key? key})
required this.imageAssetName, : super(key: key);
});
@override @override
_SwipeableCardState createState() => _SwipeableCardState(); _SwipeableCardState createState() => _SwipeableCardState();
@ -135,7 +135,7 @@ class _SwipeableCardState extends State<SwipeableCard>
onHorizontalDragStart: _dragStart, onHorizontalDragStart: _dragStart,
onHorizontalDragUpdate: _dragUpdate, onHorizontalDragUpdate: _dragUpdate,
onHorizontalDragEnd: _dragEnd, onHorizontalDragEnd: _dragEnd,
child: Card(widget.imageAssetName), child: Card(imageAssetName: widget.imageAssetName),
), ),
); );
} }

@ -7,6 +7,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
class CarouselDemo extends StatelessWidget { class CarouselDemo extends StatelessWidget {
CarouselDemo({Key? key}) : super(key: key);
static String routeName = '/misc/carousel'; static String routeName = '/misc/carousel';
static const List<String> fileNames = [ static const List<String> fileNames = [

@ -6,6 +6,7 @@ import 'dart:math' as math;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class CurvedAnimationDemo extends StatefulWidget { class CurvedAnimationDemo extends StatefulWidget {
const CurvedAnimationDemo({Key? key}) : super(key: key);
static const String routeName = '/misc/curved_animation'; static const String routeName = '/misc/curved_animation';
@override @override

@ -5,6 +5,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class ExpandCardDemo extends StatelessWidget { class ExpandCardDemo extends StatelessWidget {
const ExpandCardDemo({Key? key}) : super(key: key);
static const String routeName = '/misc/expand_card'; static const String routeName = '/misc/expand_card';
@override @override
@ -13,7 +14,7 @@ class ExpandCardDemo extends StatelessWidget {
appBar: AppBar( appBar: AppBar(
title: const Text('Expandable Card'), title: const Text('Expandable Card'),
), ),
body: Center( body: const Center(
child: ExpandCard(), child: ExpandCard(),
), ),
); );
@ -21,6 +22,7 @@ class ExpandCardDemo extends StatelessWidget {
} }
class ExpandCard extends StatefulWidget { class ExpandCard extends StatefulWidget {
const ExpandCard({Key? key}) : super(key: key);
@override @override
_ExpandCardState createState() => _ExpandCardState(); _ExpandCardState createState() => _ExpandCardState();
} }

@ -5,18 +5,20 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class FocusImageDemo extends StatelessWidget { class FocusImageDemo extends StatelessWidget {
const FocusImageDemo({Key? key}) : super(key: key);
static String routeName = '/misc/focus_image'; static String routeName = '/misc/focus_image';
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar(title: const Text('Focus Image')), appBar: AppBar(title: const Text('Focus Image')),
body: Grid(), body: const Grid(),
); );
} }
} }
class Grid extends StatelessWidget { class Grid extends StatelessWidget {
const Grid({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@ -26,8 +28,12 @@ class Grid extends StatelessWidget {
const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 4), const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 4),
itemBuilder: (context, index) { itemBuilder: (context, index) {
return (index >= 20) return (index >= 20)
? const SmallCard('assets/eat_cape_town_sm.jpg') ? const SmallCard(
: const SmallCard('assets/eat_new_orleans_sm.jpg'); imageAssetName: 'assets/eat_cape_town_sm.jpg',
)
: const SmallCard(
imageAssetName: 'assets/eat_new_orleans_sm.jpg',
);
}, },
), ),
); );
@ -66,10 +72,9 @@ Tween<RelativeRect> _createTween(BuildContext context) {
} }
class SmallCard extends StatelessWidget { class SmallCard extends StatelessWidget {
const SmallCard({required this.imageAssetName, Key? key}) : super(key: key);
final String imageAssetName; final String imageAssetName;
const SmallCard(this.imageAssetName);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Card( return Card(

@ -5,6 +5,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class HeroAnimationDemo extends StatelessWidget { class HeroAnimationDemo extends StatelessWidget {
const HeroAnimationDemo({Key? key}) : super(key: key);
static const String routeName = '/misc/hero_animation'; static const String routeName = '/misc/hero_animation';
@override @override
@ -21,14 +22,16 @@ class HeroAnimationDemo extends StatelessWidget {
color: Colors.grey.shade300, color: Colors.grey.shade300,
), ),
), ),
onTap: () => Navigator.of(context) onTap: () => Navigator.of(context).push<void>(
.push<void>(MaterialPageRoute(builder: (context) => HeroPage())), MaterialPageRoute(builder: (context) => const HeroPage())),
), ),
); );
} }
} }
class HeroPage extends StatelessWidget { class HeroPage extends StatelessWidget {
const HeroPage({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(

@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/physics.dart'; import 'package:flutter/physics.dart';
class PhysicsCardDragDemo extends StatelessWidget { class PhysicsCardDragDemo extends StatelessWidget {
const PhysicsCardDragDemo({Key? key}) : super(key: key);
static const String routeName = '/misc/physics_card'; static const String routeName = '/misc/physics_card';
@override @override
@ -26,8 +27,8 @@ class PhysicsCardDragDemo extends StatelessWidget {
/// A draggable card that moves back to [Alignment.center] when it's /// A draggable card that moves back to [Alignment.center] when it's
/// released. /// released.
class DraggableCard extends StatefulWidget { class DraggableCard extends StatefulWidget {
const DraggableCard({required this.child, Key? key}) : super(key: key);
final Widget child; final Widget child;
const DraggableCard({required this.child});
@override @override
_DraggableCardState createState() => _DraggableCardState(); _DraggableCardState createState() => _DraggableCardState();

@ -5,6 +5,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class RepeatingAnimationDemo extends StatefulWidget { class RepeatingAnimationDemo extends StatefulWidget {
const RepeatingAnimationDemo({Key? key}) : super(key: key);
static String routeName = '/misc/repeating_animation'; static String routeName = '/misc/repeating_animation';
@override @override

@ -6,7 +6,7 @@ import 'package:animations/src/misc/animated_list.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
Widget createAnimatedListDemoScreen() => MaterialApp( Widget createAnimatedListDemoScreen() => const MaterialApp(
home: AnimatedListDemo(), home: AnimatedListDemo(),
); );

@ -6,7 +6,7 @@ import 'package:animations/src/misc/animated_positioned.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
Widget createAnimatedPositionedDemoScreen() => MaterialApp( Widget createAnimatedPositionedDemoScreen() => const MaterialApp(
home: AnimatedPositionedDemo(), home: AnimatedPositionedDemo(),
); );

@ -7,7 +7,7 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
Widget createCardSwipeScreen() => MaterialApp( Widget createCardSwipeScreen() => const MaterialApp(
home: CardSwipeDemo(), home: CardSwipeDemo(),
); );

@ -6,7 +6,7 @@ import 'package:animations/src/misc/expand_card.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
Widget createExpandCardScreen() => MaterialApp( Widget createExpandCardScreen() => const MaterialApp(
home: ExpandCardDemo(), home: ExpandCardDemo(),
); );

@ -6,7 +6,7 @@ import 'package:animations/src/misc/focus_image.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
Widget createFocusImageScreen() => MaterialApp( Widget createFocusImageScreen() => const MaterialApp(
home: FocusImageDemo(), home: FocusImageDemo(),
); );

@ -6,7 +6,7 @@ import 'package:animations/src/misc/hero_animation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
Widget createHeroAnimationDemoScreen() => MaterialApp( Widget createHeroAnimationDemoScreen() => const MaterialApp(
home: HeroAnimationDemo(), home: HeroAnimationDemo(),
); );

@ -11,7 +11,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() { void main() {
testWidgets('smoke test', (tester) async { testWidgets('smoke test', (tester) async {
// Build our app and trigger a frame. // Build our app and trigger a frame.
await tester.pumpWidget(AnimationSamples()); await tester.pumpWidget(const AnimationSamples());
// Verify that a least one of our demos is showing up in the list // Verify that a least one of our demos is showing up in the list
expect(find.text('AnimatedContainer'), findsOneWidget); expect(find.text('AnimatedContainer'), findsOneWidget);

Loading…
Cancel
Save