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

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

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

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

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

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

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

@ -5,6 +5,7 @@
import 'package:flutter/material.dart';
class TweenSequenceDemo extends StatefulWidget {
const TweenSequenceDemo({Key? key}) : super(key: key);
static const String routeName = '/basics/chaining_tweens';
@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
// for examples of other common animated widgets.
class FadeTransitionDemo extends StatefulWidget {
const FadeTransitionDemo({Key? key}) : super(key: key);
static const String routeName = '/basics/fade_transition';
@override

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -11,7 +11,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('smoke test', (tester) async {
// 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
expect(find.text('AnimatedContainer'), findsOneWidget);

Loading…
Cancel
Save