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

@@ -30,7 +30,7 @@ class MyAdaptingApp extends StatelessWidget {
// Instead of letting Cupertino widgets auto-adapt to the Material
// theme (which is green), this app will use a different theme
// for Cupertino (which is blue by default).
data: CupertinoThemeData(),
data: const CupertinoThemeData(),
child: Material(child: child),
);
},
@@ -82,7 +82,7 @@ class _PlatformAdaptingHomePageState extends State<PlatformAdaptingHomePage> {
Widget _buildIosHomePage(BuildContext context) {
return CupertinoTabScaffold(
tabBar: CupertinoTabBar(
items: [
items: const [
BottomNavigationBarItem(
label: SongsTab.title,
icon: SongsTab.iosIcon,
@@ -116,7 +116,7 @@ class _PlatformAdaptingHomePageState extends State<PlatformAdaptingHomePage> {
);
default:
assert(false, 'Unexpected tab');
return SizedBox.shrink();
return const SizedBox.shrink();
}
},
);
@@ -139,7 +139,7 @@ class _AndroidDrawer extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
DrawerHeader(
decoration: BoxDecoration(color: Colors.green),
decoration: const BoxDecoration(color: Colors.green),
child: Padding(
padding: const EdgeInsets.only(bottom: 20),
child: Icon(
@@ -151,14 +151,14 @@ class _AndroidDrawer extends StatelessWidget {
),
ListTile(
leading: SongsTab.androidIcon,
title: Text(SongsTab.title),
title: const Text(SongsTab.title),
onTap: () {
Navigator.pop(context);
},
),
ListTile(
leading: NewsTab.androidIcon,
title: Text(NewsTab.title),
title: const Text(NewsTab.title),
onTap: () {
Navigator.pop(context);
Navigator.push<void>(
@@ -167,7 +167,7 @@ class _AndroidDrawer extends StatelessWidget {
),
ListTile(
leading: ProfileTab.androidIcon,
title: Text(ProfileTab.title),
title: const Text(ProfileTab.title),
onTap: () {
Navigator.pop(context);
Navigator.push<void>(context,
@@ -175,13 +175,13 @@ class _AndroidDrawer extends StatelessWidget {
},
),
// Long drawer contents are often segmented.
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
const Padding(
padding: EdgeInsets.symmetric(horizontal: 16),
child: Divider(),
),
ListTile(
leading: SettingsTab.androidIcon,
title: Text(SettingsTab.title),
title: const Text(SettingsTab.title),
onTap: () {
Navigator.pop(context);
Navigator.push<void>(context,

View File

@@ -41,7 +41,7 @@ class _NewsTabState extends State<NewsTab> {
bottom: false,
child: Card(
elevation: 1.5,
margin: EdgeInsets.fromLTRB(6, 12, 6, 0),
margin: const EdgeInsets.fromLTRB(6, 12, 6, 0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4),
),
@@ -58,22 +58,22 @@ class _NewsTabState extends State<NewsTab> {
backgroundColor: colors[index],
child: Text(
titles[index].substring(0, 1),
style: TextStyle(color: Colors.white),
style: const TextStyle(color: Colors.white),
),
),
Padding(padding: EdgeInsets.only(left: 16)),
const Padding(padding: EdgeInsets.only(left: 16)),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
titles[index],
style: TextStyle(
style: const TextStyle(
fontSize: 15,
fontWeight: FontWeight.w500,
),
),
Padding(padding: EdgeInsets.only(top: 8)),
const Padding(padding: EdgeInsets.only(top: 8)),
Text(
contents[index],
),
@@ -95,20 +95,18 @@ class _NewsTabState extends State<NewsTab> {
Widget _buildAndroid(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(NewsTab.title),
title: const Text(NewsTab.title),
),
body: Container(
child: ListView.builder(
itemCount: _itemsLength,
itemBuilder: _listBuilder,
),
body: ListView.builder(
itemCount: _itemsLength,
itemBuilder: _listBuilder,
),
);
}
Widget _buildIos(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(),
navigationBar: const CupertinoNavigationBar(),
child: ListView.builder(
itemCount: _itemsLength,
itemBuilder: _listBuilder,

View File

@@ -19,7 +19,7 @@ class ProfileTab extends StatelessWidget {
padding: const EdgeInsets.all(24.0),
child: Column(
children: [
Padding(
const Padding(
padding: EdgeInsets.all(8),
child: Center(
child: Text(
@@ -31,7 +31,7 @@ class ProfileTab extends StatelessWidget {
),
),
),
PreferenceCard(
const PreferenceCard(
header: 'MY INTENSITY PREFERENCE',
content: '🔥',
preferenceChoices: [
@@ -42,7 +42,7 @@ class ProfileTab extends StatelessWidget {
'My neighbor hates me',
],
),
PreferenceCard(
const PreferenceCard(
header: 'CURRENT MOOD',
content: '🤘🏾🚀',
preferenceChoices: [
@@ -70,7 +70,7 @@ class ProfileTab extends StatelessWidget {
Widget _buildAndroid(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
title: const Text(title),
),
body: _buildBody(context),
);
@@ -123,18 +123,18 @@ class PreferenceCard extends StatelessWidget {
Widget build(context) {
return PressableCard(
color: Colors.green,
flattenAnimation: AlwaysStoppedAnimation(0),
flattenAnimation: const AlwaysStoppedAnimation(0),
child: Stack(
children: [
Container(
SizedBox(
height: 120,
width: 250,
child: Padding(
padding: EdgeInsets.only(top: 40),
padding: const EdgeInsets.only(top: 40),
child: Center(
child: Text(
content,
style: TextStyle(fontSize: 48),
style: const TextStyle(fontSize: 48),
),
),
),
@@ -146,11 +146,11 @@ class PreferenceCard extends StatelessWidget {
child: Container(
color: Colors.black12,
height: 40,
padding: EdgeInsets.only(left: 12),
padding: const EdgeInsets.only(left: 12),
alignment: Alignment.centerLeft,
child: Text(
header,
style: TextStyle(
style: const TextStyle(
color: Colors.white,
fontSize: 14,
fontWeight: FontWeight.w600,
@@ -182,7 +182,7 @@ class LogOutButton extends StatelessWidget {
Widget _buildAndroid(BuildContext context) {
return ElevatedButton(
child: Text('LOG OUT', style: TextStyle(color: Colors.red)),
child: const Text('LOG OUT', style: TextStyle(color: Colors.red)),
onPressed: () {
// You should do something with the result of the dialog prompt in a
// real app but this is just a demo.
@@ -190,7 +190,7 @@ class LogOutButton extends StatelessWidget {
context: context,
builder: (context) {
return AlertDialog(
title: Text('Log out?'),
title: const Text('Log out?'),
content: _logoutMessage,
actions: [
TextButton(
@@ -212,7 +212,7 @@ class LogOutButton extends StatelessWidget {
Widget _buildIos(BuildContext context) {
return CupertinoButton(
color: CupertinoColors.destructiveRed,
child: Text('Log out'),
child: const Text('Log out'),
onPressed: () {
// You should do something with the result of the action sheet prompt
// in a real app but this is just a demo.
@@ -220,7 +220,7 @@ class LogOutButton extends StatelessWidget {
context: context,
builder: (context) {
return CupertinoActionSheet(
title: Text('Log out?'),
title: const Text('Log out?'),
message: _logoutMessage,
actions: [
CupertinoActionSheetAction(

View File

@@ -28,9 +28,9 @@ class _SettingsTabState extends State<SettingsTab> {
Widget _buildList() {
return ListView(
children: [
Padding(padding: EdgeInsets.only(top: 24)),
const Padding(padding: EdgeInsets.only(top: 24)),
ListTile(
title: Text('Send me marketing emails'),
title: const Text('Send me marketing emails'),
// The Material switch has a platform adaptive constructor.
trailing: Switch.adaptive(
value: switch1,
@@ -38,42 +38,42 @@ class _SettingsTabState extends State<SettingsTab> {
),
),
ListTile(
title: Text('Enable notifications'),
title: const Text('Enable notifications'),
trailing: Switch.adaptive(
value: switch2,
onChanged: (value) => setState(() => switch2 = value),
),
),
ListTile(
title: Text('Remind me to rate this app'),
title: const Text('Remind me to rate this app'),
trailing: Switch.adaptive(
value: switch3,
onChanged: (value) => setState(() => switch3 = value),
),
),
ListTile(
title: Text('Background song refresh'),
title: const Text('Background song refresh'),
trailing: Switch.adaptive(
value: switch4,
onChanged: (value) => setState(() => switch4 = value),
),
),
ListTile(
title: Text('Recommend me songs based on my location'),
title: const Text('Recommend me songs based on my location'),
trailing: Switch.adaptive(
value: switch5,
onChanged: (value) => setState(() => switch5 = value),
),
),
ListTile(
title: Text('Auto-transition playback to cast devices'),
title: const Text('Auto-transition playback to cast devices'),
trailing: Switch.adaptive(
value: switch6,
onChanged: (value) => setState(() => switch6 = value),
),
),
ListTile(
title: Text('Find friends from my contact list'),
title: const Text('Find friends from my contact list'),
trailing: Switch.adaptive(
value: switch7,
onChanged: (value) => setState(() => switch7 = value),
@@ -90,7 +90,7 @@ class _SettingsTabState extends State<SettingsTab> {
Widget _buildAndroid(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(SettingsTab.title),
title: const Text(SettingsTab.title),
),
body: _buildList(),
);
@@ -98,7 +98,7 @@ class _SettingsTabState extends State<SettingsTab> {
Widget _buildIos(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(),
navigationBar: const CupertinoNavigationBar(),
child: _buildList(),
);
}

View File

@@ -35,7 +35,7 @@ class SongDetailTab extends StatelessWidget {
child: HeroAnimatingSongCard(
song: song,
color: color,
heroAnimation: AlwaysStoppedAnimation(1),
heroAnimation: const AlwaysStoppedAnimation(1),
),
// This app uses a flightShuttleBuilder to specify the exact widget
// to build while the hero transition is mid-flight.
@@ -50,7 +50,7 @@ class SongDetailTab extends StatelessWidget {
);
},
),
Divider(
const Divider(
height: 0,
color: Colors.grey,
),
@@ -59,9 +59,8 @@ class SongDetailTab extends StatelessWidget {
itemCount: 10,
itemBuilder: (context, index) {
if (index == 0) {
return Padding(
padding:
const EdgeInsets.only(left: 15, top: 16, bottom: 8),
return const Padding(
padding: EdgeInsets.only(left: 15, top: 16, bottom: 8),
child: Text(
'You might also like:',
style: TextStyle(

View File

@@ -67,7 +67,7 @@ class _SongsTabState extends State<SongsTab> {
child: HeroAnimatingSongCard(
song: songNames[index],
color: color,
heroAnimation: AlwaysStoppedAnimation(0),
heroAnimation: const AlwaysStoppedAnimation(0),
onPressed: () => Navigator.of(context).push<void>(
MaterialPageRoute(
builder: (context) => SongDetailTab(
@@ -113,15 +113,15 @@ class _SongsTabState extends State<SongsTab> {
Widget _buildAndroid(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(SongsTab.title),
title: const Text(SongsTab.title),
actions: [
IconButton(
icon: Icon(Icons.refresh),
icon: const Icon(Icons.refresh),
onPressed: () async =>
await _androidRefreshKey.currentState!.show(),
),
IconButton(
icon: Icon(Icons.shuffle),
icon: const Icon(Icons.shuffle),
onPressed: _togglePlatform,
),
],
@@ -131,7 +131,7 @@ class _SongsTabState extends State<SongsTab> {
key: _androidRefreshKey,
onRefresh: _refreshData,
child: ListView.builder(
padding: EdgeInsets.symmetric(vertical: 12),
padding: const EdgeInsets.symmetric(vertical: 12),
itemCount: _itemsLength,
itemBuilder: _listBuilder,
),
@@ -145,7 +145,7 @@ class _SongsTabState extends State<SongsTab> {
CupertinoSliverNavigationBar(
trailing: CupertinoButton(
padding: EdgeInsets.zero,
child: Icon(CupertinoIcons.shuffle),
child: const Icon(CupertinoIcons.shuffle),
onPressed: _togglePlatform,
),
),
@@ -155,7 +155,7 @@ class _SongsTabState extends State<SongsTab> {
SliverSafeArea(
top: false,
sliver: SliverPadding(
padding: EdgeInsets.symmetric(vertical: 12),
padding: const EdgeInsets.symmetric(vertical: 12),
sliver: SliverList(
delegate: SliverChildBuilderDelegate(
_listBuilder,

View File

@@ -26,7 +26,7 @@ class PlatformWidget extends StatelessWidget {
return iosBuilder(context);
default:
assert(false, 'Unexpected platform $defaultTargetPlatform');
return SizedBox.shrink();
return const SizedBox.shrink();
}
}
}
@@ -107,8 +107,9 @@ class _PressableCardState extends State<PressableCard>
// in your own app.
scale: 1 - elevationAnimation.value * 0.03,
child: Padding(
padding: EdgeInsets.symmetric(vertical: 16, horizontal: 16) *
flatten,
padding:
const EdgeInsets.symmetric(vertical: 16, horizontal: 16) *
flatten,
child: PhysicalModel(
elevation:
((1 - elevationAnimation.value) * 10 + 10) * flatten,
@@ -134,7 +135,7 @@ class _PressableCardState extends State<PressableCard>
/// This is an example of a custom widget that an app developer might create for
/// use on both iOS and Android as part of their brand's unique design.
class HeroAnimatingSongCard extends StatelessWidget {
HeroAnimatingSongCard({
const HeroAnimatingSongCard({
required this.song,
required this.color,
required this.heroAnimation,
@@ -177,10 +178,10 @@ class HeroAnimatingSongCard extends StatelessWidget {
height: 80,
color: Colors.black12,
alignment: Alignment.centerLeft,
padding: EdgeInsets.symmetric(horizontal: 12),
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Text(
song,
style: TextStyle(
style: const TextStyle(
fontSize: 21,
fontWeight: FontWeight.w500,
),
@@ -189,12 +190,12 @@ class HeroAnimatingSongCard extends StatelessWidget {
),
// The play button grows in the hero animation.
Padding(
padding:
EdgeInsets.only(bottom: 45) * (1 - heroAnimation.value),
padding: const EdgeInsets.only(bottom: 45) *
(1 - heroAnimation.value),
child: Container(
height: playButtonSize,
width: playButtonSize,
decoration: BoxDecoration(
decoration: const BoxDecoration(
shape: BoxShape.circle,
color: Colors.black12,
),
@@ -222,14 +223,14 @@ class SongPlaceholderTile extends StatelessWidget {
return SizedBox(
height: 95,
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 15, vertical: 8),
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 8),
child: Row(
children: [
Container(
color: Theme.of(context).textTheme.bodyText2!.color,
width: 130,
),
Padding(
const Padding(
padding: EdgeInsets.only(left: 12),
),
Expanded(
@@ -238,27 +239,27 @@ class SongPlaceholderTile extends StatelessWidget {
children: [
Container(
height: 9,
margin: EdgeInsets.only(right: 60),
margin: const EdgeInsets.only(right: 60),
color: Theme.of(context).textTheme.bodyText2!.color,
),
Container(
height: 9,
margin: EdgeInsets.only(right: 20, top: 8),
margin: const EdgeInsets.only(right: 20, top: 8),
color: Theme.of(context).textTheme.bodyText2!.color,
),
Container(
height: 9,
margin: EdgeInsets.only(right: 40, top: 8),
margin: const EdgeInsets.only(right: 40, top: 8),
color: Theme.of(context).textTheme.bodyText2!.color,
),
Container(
height: 9,
margin: EdgeInsets.only(right: 80, top: 8),
margin: const EdgeInsets.only(right: 80, top: 8),
color: Theme.of(context).textTheme.bodyText2!.color,
),
Container(
height: 9,
margin: EdgeInsets.only(right: 50, top: 8),
margin: const EdgeInsets.only(right: 50, top: 8),
color: Theme.of(context).textTheme.bodyText2!.color,
),
],
@@ -289,7 +290,7 @@ void showChoices(BuildContext context, List<String> choices) {
builder: (context) {
int? selectedRadio = 1;
return AlertDialog(
contentPadding: EdgeInsets.only(top: 12),
contentPadding: const EdgeInsets.only(top: 12),
content: StatefulBuilder(
builder: (context, setState) {
return Column(
@@ -309,11 +310,11 @@ void showChoices(BuildContext context, List<String> choices) {
),
actions: [
TextButton(
child: Text('OK'),
child: const Text('OK'),
onPressed: () => Navigator.of(context).pop(),
),
TextButton(
child: Text('CANCEL'),
child: const Text('CANCEL'),
onPressed: () => Navigator.of(context).pop(),
),
],
@@ -337,7 +338,7 @@ void showChoices(BuildContext context, List<String> choices) {
return Center(
child: Text(
choices[index],
style: TextStyle(
style: const TextStyle(
fontSize: 21,
),
),