1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-08 13:58:47 +00:00

Upgrading samples to flutter_lints, part 1 of n (#804)

This commit is contained in:
Brett Morgan
2021-06-05 12:24:28 +10:00
committed by GitHub
parent 14921d0c06
commit 936d1fdaae
230 changed files with 2361 additions and 2444 deletions

View File

@@ -151,7 +151,7 @@ class HomePage extends StatelessWidget {
final headerStyle = Theme.of(context).textTheme.headline6;
return Scaffold(
appBar: AppBar(
title: Text('Animation Samples'),
title: const Text('Animation Samples'),
),
body: ListView(
children: [
@@ -168,7 +168,7 @@ class HomePage extends StatelessWidget {
class DemoTile extends StatelessWidget {
final Demo demo;
DemoTile(this.demo);
const DemoTile(this.demo);
@override
Widget build(BuildContext context) {

View File

@@ -49,13 +49,13 @@ class _AnimatedContainerDemoState extends State<AnimatedContainerDemo> {
// and shrinking cards.
return Scaffold(
appBar: AppBar(
title: Text('AnimatedContainer'),
title: const Text('AnimatedContainer'),
),
body: Center(
child: Column(
children: [
Padding(
padding: EdgeInsets.all(8.0),
padding: const EdgeInsets.all(8.0),
child: SizedBox(
width: 128,
height: 128,
@@ -70,7 +70,7 @@ class _AnimatedContainerDemoState extends State<AnimatedContainerDemo> {
),
),
ElevatedButton(
child: Text(
child: const Text(
'change',
),
onPressed: () => change(),

View File

@@ -11,11 +11,11 @@ class PageRouteBuilderDemo extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Page 1'),
title: const Text('Page 1'),
),
body: Center(
child: ElevatedButton(
child: Text('Go!'),
child: const Text('Go!'),
onPressed: () {
Navigator.of(context).push<void>(_createRoute());
},
@@ -29,7 +29,8 @@ Route _createRoute() {
return PageRouteBuilder<SlideTransition>(
pageBuilder: (context, animation, secondaryAnimation) => _Page2(),
transitionsBuilder: (context, animation, secondaryAnimation, child) {
var tween = Tween<Offset>(begin: Offset(0.0, 1.0), end: Offset.zero);
var tween =
Tween<Offset>(begin: const Offset(0.0, 1.0), end: Offset.zero);
var curveTween = CurveTween(curve: Curves.ease);
return SlideTransition(
@@ -45,7 +46,7 @@ class _Page2 extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Page 2'),
title: const Text('Page 2'),
),
body: Center(
child: Text('Page 2!', style: Theme.of(context).textTheme.headline4),

View File

@@ -54,22 +54,22 @@ class _AnimationControllerDemoState extends State<AnimationControllerDemo>
// has completed.
return Scaffold(
appBar: AppBar(
title: Text('Animation Controller'),
title: const Text('Animation Controller'),
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ConstrainedBox(
constraints: BoxConstraints(maxWidth: 200),
constraints: const BoxConstraints(maxWidth: 200),
child: Text(
'${controller.value.toStringAsFixed(2)}',
controller.value.toStringAsFixed(2),
style: Theme.of(context).textTheme.headline3,
textScaleFactor: 1 + controller.value,
),
),
ElevatedButton(
child: Text('animate'),
child: const Text('animate'),
onPressed: () {
if (controller.status == AnimationStatus.completed) {
controller.reverse();

View File

@@ -40,16 +40,16 @@ class _TweenDemoState extends State<TweenDemo>
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Tweens'),
title: const Text('Tweens'),
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ConstrainedBox(
constraints: BoxConstraints(maxWidth: 200),
constraints: const BoxConstraints(maxWidth: 200),
child: Text('\$${animation.value.toStringAsFixed(2)}',
style: TextStyle(fontSize: 24)),
style: const TextStyle(fontSize: 24)),
),
ElevatedButton(
child: Text(

View File

@@ -15,7 +15,7 @@ class _AnimatedBuilderDemoState extends State<AnimatedBuilderDemo>
with SingleTickerProviderStateMixin {
static const Color beginColor = Colors.deepPurple;
static const Color endColor = Colors.deepOrange;
Duration duration = Duration(milliseconds: 800);
Duration duration = const Duration(milliseconds: 800);
late AnimationController controller;
late Animation<Color?> animation;
@@ -38,7 +38,7 @@ class _AnimatedBuilderDemoState extends State<AnimatedBuilderDemo>
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('AnimatedBuilder'),
title: const Text('AnimatedBuilder'),
),
body: Center(
// AnimatedBuilder handles listening to a given animation and calling the builder
@@ -66,7 +66,7 @@ class _AnimatedBuilderDemoState extends State<AnimatedBuilderDemo>
// if there is a non-animated Widget contained within the animated widget.
// This can improve performance since this widget doesn't need to be rebuilt
// when the animation changes.
child: Text(
child: const Text(
'Change Color',
style: TextStyle(color: Colors.white),
),

View File

@@ -47,7 +47,7 @@ class _CustomTweenDemoState extends State<CustomTweenDemo>
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Custom Tween'),
title: const Text('Custom Tween'),
actions: [
MaterialButton(
child: Text(
@@ -79,16 +79,18 @@ class _CustomTweenDemoState extends State<CustomTweenDemo>
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: EdgeInsets.all(8.0),
padding: const EdgeInsets.all(8.0),
child: Card(
child: Container(
padding: EdgeInsets.all(8.0),
padding: const EdgeInsets.all(8.0),
child: AnimatedBuilder(
animation: animation,
builder: (context, child) {
return Text('${animation.value}',
style: TextStyle(
fontSize: 16, fontFamily: 'SpecialElite'));
return Text(
animation.value,
style: const TextStyle(
fontSize: 16, fontFamily: 'SpecialElite'),
);
},
),
),

View File

@@ -60,7 +60,7 @@ class _TweenSequenceDemoState extends State<TweenSequenceDemo>
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Tween Sequences'),
title: const Text('Tween Sequences'),
),
body: Center(
child: AnimatedBuilder(
@@ -75,7 +75,7 @@ class _TweenSequenceDemoState extends State<TweenSequenceDemo>
child: child,
);
},
child: Text('Animate', style: TextStyle(color: Colors.white)),
child: const Text('Animate', style: TextStyle(color: Colors.white)),
),
),
);

View File

@@ -24,7 +24,7 @@ class _FadeTransitionDemoState extends State<FadeTransitionDemo>
super.initState();
_controller = AnimationController(
vsync: this,
duration: Duration(milliseconds: 500),
duration: const Duration(milliseconds: 500),
);
_curve = CurvedAnimation(parent: _controller, curve: Curves.easeIn);
@@ -45,7 +45,7 @@ class _FadeTransitionDemoState extends State<FadeTransitionDemo>
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
title: const Text(
'Fade Transition',
),
),
@@ -55,14 +55,14 @@ class _FadeTransitionDemoState extends State<FadeTransitionDemo>
children: <Widget>[
FadeTransition(
opacity: _animation,
child: Icon(
child: const Icon(
Icons.star,
color: Colors.amber,
size: 300,
),
),
ElevatedButton(
child: Text('animate'),
child: const Text('animate'),
onPressed: () => setState(() {
_controller.animateTo(1.0).then<TickerFuture>(
(value) => _controller.animateBack(0.0));

View File

@@ -30,7 +30,7 @@ class _AnimatedListDemoState extends State<AnimatedListDemo> {
UserModel(++_maxIdValue, 'New', 'Person'),
);
_listKey.currentState!
.insertItem(index, duration: Duration(milliseconds: 300));
.insertItem(index, duration: const Duration(milliseconds: 300));
});
}
@@ -42,17 +42,17 @@ class _AnimatedListDemoState extends State<AnimatedListDemo> {
index,
(context, animation) {
return FadeTransition(
opacity:
CurvedAnimation(parent: animation, curve: Interval(0.5, 1.0)),
opacity: CurvedAnimation(
parent: animation, curve: const Interval(0.5, 1.0)),
child: SizeTransition(
sizeFactor:
CurvedAnimation(parent: animation, curve: Interval(0.0, 1.0)),
sizeFactor: CurvedAnimation(
parent: animation, curve: const Interval(0.0, 1.0)),
axisAlignment: 0.0,
child: _buildItem(user),
),
);
},
duration: Duration(milliseconds: 600),
duration: const Duration(milliseconds: 600),
);
});
}
@@ -62,11 +62,11 @@ class _AnimatedListDemoState extends State<AnimatedListDemo> {
key: ValueKey<UserModel>(user),
title: Text(user.firstName),
subtitle: Text(user.lastName),
leading: CircleAvatar(
leading: const CircleAvatar(
child: Icon(Icons.person),
),
trailing: IconButton(
icon: Icon(Icons.delete),
icon: const Icon(Icons.delete),
onPressed: () => deleteUser(user.id),
),
);
@@ -76,10 +76,10 @@ class _AnimatedListDemoState extends State<AnimatedListDemo> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('AnimatedList'),
title: const Text('AnimatedList'),
actions: <Widget>[
IconButton(
icon: Icon(Icons.add),
icon: const Icon(Icons.add),
onPressed: addUser,
),
],

View File

@@ -38,12 +38,12 @@ class _AnimatedPositionedDemoState extends State<AnimatedPositionedDemo> {
@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
final appBar = AppBar(title: Text('AnimatedPositioned'));
final appBar = AppBar(title: const Text('AnimatedPositioned'));
final topPadding = MediaQuery.of(context).padding.top;
// AnimatedPositioned animates changes to a widget's position within a Stack
return Scaffold(
appBar: appBar,
body: Container(
body: SizedBox(
height: size.height,
width: size.width,
child: Stack(
@@ -51,7 +51,7 @@ class _AnimatedPositionedDemoState extends State<AnimatedPositionedDemo> {
AnimatedPositioned(
top: topPosition,
left: leftPosition,
duration: Duration(seconds: 1),
duration: const Duration(seconds: 1),
child: InkWell(
onTap: () => changePosition(
size.height -

View File

@@ -44,7 +44,7 @@ class _AnimatedSwitcherDemoState extends State<AnimatedSwitcherDemo> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('AnimatedSwitcher'),
title: const Text('AnimatedSwitcher'),
actions: [
MaterialButton(
onPressed: () => setState(
@@ -63,7 +63,7 @@ class _AnimatedSwitcherDemoState extends State<AnimatedSwitcherDemo> {
// with a given transition. You can change the transitions by using
// transitionBuilder property.
child: AnimatedSwitcher(
duration: Duration(seconds: 1),
duration: const Duration(seconds: 1),
child: container,
transitionBuilder: (child, animation) => ScaleTransition(
child: child,

View File

@@ -35,7 +35,7 @@ class _CardSwipeDemoState extends State<CardSwipeDemo> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Card Swipe'),
title: const Text('Card Swipe'),
),
body: Padding(
padding: const EdgeInsets.all(12.0),
@@ -78,7 +78,7 @@ class _CardSwipeDemoState extends State<CardSwipeDemo> {
class Card extends StatelessWidget {
final String imageAssetName;
Card(this.imageAssetName);
const Card(this.imageAssetName);
@override
Widget build(BuildContext context) {
@@ -101,7 +101,7 @@ class SwipeableCard extends StatefulWidget {
final String imageAssetName;
final VoidCallback onSwiped;
SwipeableCard({
const SwipeableCard({
required this.onSwiped,
required this.imageAssetName,
});
@@ -123,7 +123,7 @@ class _SwipeableCardState extends State<SwipeableCard>
_controller = AnimationController.unbounded(vsync: this);
_animation = _controller.drive(Tween<Offset>(
begin: Offset.zero,
end: Offset(1, 0),
end: const Offset(1, 0),
));
}
@@ -184,12 +184,13 @@ class _SwipeableCardState extends State<SwipeableCard>
void _updateAnimation(double dragPosition) {
_animation = _controller.drive(Tween<Offset>(
begin: Offset.zero,
end: _isSwipingLeft ? Offset(-1, 0) : Offset(1, 0),
end: _isSwipingLeft ? const Offset(-1, 0) : const Offset(1, 0),
));
}
void _animate({double velocity = 0}) {
var description = SpringDescription(mass: 50, stiffness: 1, damping: 1);
var description =
const SpringDescription(mass: 50, stiffness: 1, damping: 1);
var simulation =
SpringSimulation(description, _controller.value, 1, velocity);
_controller.animateWith(simulation).then<void>((_) {

View File

@@ -22,7 +22,7 @@ class CarouselDemo extends StatelessWidget {
Widget build(context) {
return Scaffold(
appBar: AppBar(
title: Text('Carousel Demo'),
title: const Text('Carousel Demo'),
),
body: Center(
child: Padding(

View File

@@ -25,7 +25,7 @@ class _CurvedAnimationDemoState extends State<CurvedAnimationDemo>
late final Animation<double> animationRotation;
late final Animation<Offset> animationTranslation;
static const _duration = Duration(seconds: 4);
List<CurveChoice> curves = [
List<CurveChoice> curves = const [
CurveChoice(curve: Curves.bounceIn, name: 'Bounce In'),
CurveChoice(curve: Curves.bounceOut, name: 'Bounce Out'),
CurveChoice(curve: Curves.easeInCubic, name: 'Ease In Cubic'),
@@ -69,8 +69,8 @@ class _CurvedAnimationDemoState extends State<CurvedAnimationDemo>
}
});
animationTranslation = Tween<Offset>(
begin: Offset(-1, 0),
end: Offset(1, 0),
begin: const Offset(-1, 0),
end: const Offset(1, 0),
).animate(curvedAnimation)
..addListener(() {
setState(() {});
@@ -86,11 +86,11 @@ class _CurvedAnimationDemoState extends State<CurvedAnimationDemo>
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Curved Animation'),
title: const Text('Curved Animation'),
),
body: Column(
children: [
SizedBox(height: 20.0),
const SizedBox(height: 20.0),
Text(
'Select Curve for forward motion',
style: Theme.of(context).textTheme.headline6,
@@ -110,7 +110,7 @@ class _CurvedAnimationDemoState extends State<CurvedAnimationDemo>
},
value: selectedForwardCurve,
),
SizedBox(height: 15.0),
const SizedBox(height: 15.0),
Text(
'Select Curve for reverse motion',
style: Theme.of(context).textTheme.headline6,
@@ -130,32 +130,28 @@ class _CurvedAnimationDemoState extends State<CurvedAnimationDemo>
},
value: selectedReverseCurve,
),
SizedBox(height: 35.0),
const SizedBox(height: 35.0),
Transform.rotate(
angle: animationRotation.value,
child: Center(
child: Container(
child: FlutterLogo(
size: 100,
),
),
),
),
SizedBox(height: 35.0),
FractionalTranslation(
translation: animationTranslation.value,
child: Container(
child: const Center(
child: FlutterLogo(
size: 100,
),
),
),
SizedBox(height: 25.0),
const SizedBox(height: 35.0),
FractionalTranslation(
translation: animationTranslation.value,
child: const FlutterLogo(
size: 100,
),
),
const SizedBox(height: 25.0),
ElevatedButton(
onPressed: () {
controller.forward();
},
child: Text('Animate'),
child: const Text('Animate'),
),
],
),

View File

@@ -11,7 +11,7 @@ class ExpandCardDemo extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Expandable Card'),
title: const Text('Expandable Card'),
),
body: Center(
child: ExpandCard(),

View File

@@ -10,7 +10,7 @@ class FocusImageDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Focus Image')),
appBar: AppBar(title: const Text('Focus Image')),
body: Grid(),
);
}
@@ -23,11 +23,11 @@ class Grid extends StatelessWidget {
body: GridView.builder(
itemCount: 40,
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 4),
const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 4),
itemBuilder: (context, index) {
return (index >= 20)
? SmallCard('assets/eat_cape_town_sm.jpg')
: SmallCard('assets/eat_new_orleans_sm.jpg');
? const SmallCard('assets/eat_cape_town_sm.jpg')
: const SmallCard('assets/eat_new_orleans_sm.jpg');
},
),
);
@@ -68,7 +68,7 @@ Tween<RelativeRect> _createTween(BuildContext context) {
class SmallCard extends StatelessWidget {
final String imageAssetName;
SmallCard(this.imageAssetName);
const SmallCard(this.imageAssetName);
@override
Widget build(BuildContext context) {
@@ -92,7 +92,7 @@ class SmallCard extends StatelessWidget {
class _SecondPage extends StatelessWidget {
final String imageAssetName;
_SecondPage(this.imageAssetName);
const _SecondPage(this.imageAssetName);
@override
Widget build(BuildContext context) {

View File

@@ -11,7 +11,7 @@ class HeroAnimationDemo extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Hero Animation'),
title: const Text('Hero Animation'),
),
body: GestureDetector(
child: Hero(
@@ -54,12 +54,12 @@ StatelessWidget _createHeroContainer({
return Container(
height: size,
width: size,
padding: EdgeInsets.all(10.0),
margin: size < 100.0 ? EdgeInsets.all(10.0) : EdgeInsets.all(0),
padding: const EdgeInsets.all(10.0),
margin: size < 100.0 ? const EdgeInsets.all(10.0) : const EdgeInsets.all(0),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: color,
),
child: FlutterLogo(),
child: const FlutterLogo(),
);
}

View File

@@ -12,9 +12,9 @@ class PhysicsCardDragDemo extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Spring Physics'),
title: const Text('Spring Physics'),
),
body: DraggableCard(
body: const DraggableCard(
child: FlutterLogo(
size: 128,
),
@@ -27,7 +27,7 @@ class PhysicsCardDragDemo extends StatelessWidget {
/// released.
class DraggableCard extends StatefulWidget {
final Widget child;
DraggableCard({required this.child});
const DraggableCard({required this.child});
@override
_DraggableCardState createState() => _DraggableCardState();

View File

@@ -33,7 +33,7 @@ class RepeatingAnimationDemoState extends State<RepeatingAnimationDemo>
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Repeating Animation')),
appBar: AppBar(title: const Text('Repeating Animation')),
body: Center(
child: AnimatedBuilder(
animation: _borderRadius,