mirror of
https://github.com/flutter/samples.git
synced 2026-04-04 10:41:55 +00:00
Upgrading samples to flutter_lints, part 1 of n (#804)
This commit is contained in:
@@ -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,
|
||||
),
|
||||
],
|
||||
|
||||
@@ -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 -
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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>((_) {
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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'),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user