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

@@ -68,7 +68,7 @@ class HomePage extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Platform Channel Sample'),
title: const Text('Platform Channel Sample'),
),
body: ListView(
children: demoList.map((demoInfo) => DemoTile(demoInfo)).toList(),
@@ -81,7 +81,7 @@ class HomePage extends StatelessWidget {
class DemoTile extends StatelessWidget {
final DemoInfo demoInfo;
DemoTile(this.demoInfo);
const DemoTile(this.demoInfo);
@override
Widget build(BuildContext context) {

View File

@@ -8,7 +8,7 @@ import 'package:flutter/services.dart';
/// changes from the Accelerometer sensor from native side. It has a [readings]
/// getter to provide a stream of [AccelerometerReadings].
class Accelerometer {
static final _eventChannel = const EventChannel('eventChannelDemo');
static const _eventChannel = EventChannel('eventChannelDemo');
/// Method responsible for providing a stream of [AccelerometerReadings] to listen
/// to value changes from the Accelerometer sensor.

View File

@@ -22,10 +22,10 @@ class _AddPetDetailsState extends State<AddPetDetails> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Add Pet Details'),
title: const Text('Add Pet Details'),
actions: <Widget>[
IconButton(
icon: Icon(Icons.add),
icon: const Icon(Icons.add),
onPressed: () {
PetListMessageChannel.addPetDetails(
PetDetails(
@@ -43,19 +43,19 @@ class _AddPetDetailsState extends State<AddPetDetails> {
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
SizedBox(
const SizedBox(
height: 8,
),
TextField(
controller: breedTextController,
decoration: InputDecoration(
decoration: const InputDecoration(
border: OutlineInputBorder(),
filled: true,
hintText: 'Breed of pet',
labelText: 'Breed',
),
),
SizedBox(
const SizedBox(
height: 8,
),
RadioListTile<String>(

View File

@@ -19,7 +19,7 @@ class EventChannelDemo extends StatelessWidget {
final textStyle = Theme.of(context).textTheme.headline5;
return Scaffold(
appBar: AppBar(
title: Text('EventChannel Demo'),
title: const Text('EventChannel Demo'),
),
body: Center(
child: StreamBuilder<AccelerometerReadings>(

View File

@@ -10,8 +10,8 @@ import 'package:flutter/services.dart';
/// from a native asset. The [BasicMessageChannel] uses [StandardMessageCodec]
/// since it supports [Uint8List], which is used to transport the image data.
class PlatformImageFetcher {
static final _basicMessageChannel = const BasicMessageChannel<dynamic>(
'platformImageDemo', StandardMessageCodec());
static const _basicMessageChannel =
BasicMessageChannel<dynamic>('platformImageDemo', StandardMessageCodec());
/// Method responsible for providing the platform image.
static Future<Uint8List> getImage() async {

View File

@@ -29,7 +29,7 @@ class _MethodChannelDemoState extends State<MethodChannelDemo> {
'Value of count is $count',
style: Theme.of(context).textTheme.headline5,
),
SizedBox(
const SizedBox(
height: 16,
),
Row(
@@ -49,8 +49,8 @@ class _MethodChannelDemoState extends State<MethodChannelDemo> {
);
}
},
icon: Icon(Icons.add),
label: Text('Increment'),
icon: const Icon(Icons.add),
label: const Text('Increment'),
),
// Whenever users press the ElevatedButton, it invokes
@@ -67,8 +67,8 @@ class _MethodChannelDemoState extends State<MethodChannelDemo> {
);
}
},
icon: Icon(Icons.remove),
label: Text('Decrement'),
icon: const Icon(Icons.remove),
label: const Text('Decrement'),
)
],
)

View File

@@ -9,10 +9,10 @@ import 'package:flutter/services.dart';
/// This class includes two methods [addPetDetails] and [removePet] which are used
/// to add a new pet and remove a pet from the the list respectively.
class PetListMessageChannel {
static final _jsonMessageCodecChannel =
static const _jsonMessageCodecChannel =
BasicMessageChannel<dynamic>('jsonMessageCodecDemo', JSONMessageCodec());
static final _binaryCodecChannel =
static const _binaryCodecChannel =
BasicMessageChannel('binaryCodecDemo', BinaryCodec());
/// Method to add a new pet to the list.

View File

@@ -22,7 +22,7 @@ class _PetListScreenState extends State<PetListScreen> {
super.initState();
// Receives a string of json object from the platform and converts it
// to PetModel.
BasicMessageChannel('stringCodecDemo', StringCodec())
const BasicMessageChannel('stringCodecDemo', StringCodec())
.setMessageHandler((message) async {
if (message == null) {
showSnackBar('An error occurred while adding pet details.', context);
@@ -40,16 +40,16 @@ class _PetListScreenState extends State<PetListScreen> {
return Scaffold(
key: scaffoldKey,
appBar: AppBar(
title: Text('Pet List'),
title: const Text('Pet List'),
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
child: const Icon(Icons.add),
onPressed: () {
Navigator.pushNamed(context, '/addPetDetails');
},
),
body: petListModel?.petList?.isEmpty ?? true
? Center(child: Text('Enter Pet Details'))
? const Center(child: Text('Enter Pet Details'))
: BuildPetList(petListModel.petList),
);
}
@@ -59,12 +59,12 @@ class _PetListScreenState extends State<PetListScreen> {
class BuildPetList extends StatelessWidget {
final List<PetDetails> petList;
BuildPetList(this.petList);
const BuildPetList(this.petList);
@override
Widget build(BuildContext context) {
return ListView.builder(
padding: EdgeInsets.all(8),
padding: const EdgeInsets.all(8),
itemCount: petList.length,
itemBuilder: (context, index) {
return ListTile(
@@ -73,7 +73,7 @@ class BuildPetList extends StatelessWidget {
'Pet type: ${petList[index].petType}',
),
trailing: IconButton(
icon: Icon(Icons.delete),
icon: const Icon(Icons.delete),
onPressed: () async {
try {
await PetListMessageChannel.removePet(index);

View File

@@ -24,7 +24,7 @@ class _PlatformImageDemoState extends State<PlatformImageDemo> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Platform Image Demo'),
title: const Text('Platform Image Demo'),
),
body: Center(
child: Column(
@@ -38,7 +38,7 @@ class _PlatformImageDemoState extends State<PlatformImageDemo> {
future: imageData,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.none) {
return Placeholder();
return const Placeholder();
} else if (snapshot.hasError) {
return Center(
child: Text(snapshot.error.toString()),
@@ -50,12 +50,12 @@ class _PlatformImageDemoState extends State<PlatformImageDemo> {
fit: BoxFit.fill,
);
}
return CircularProgressIndicator();
return const CircularProgressIndicator();
},
),
),
),
SizedBox(
const SizedBox(
height: 16,
),
ElevatedButton(
@@ -66,7 +66,7 @@ class _PlatformImageDemoState extends State<PlatformImageDemo> {
imageData = PlatformImageFetcher.getImage();
});
},
child: Text('Get Image'),
child: const Text('Get Image'),
)
],
),