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:
@@ -1,4 +1,4 @@
|
||||
include: package:pedantic/analysis_options.yaml
|
||||
include: package:flutter_lints/flutter.yaml
|
||||
|
||||
analyzer:
|
||||
strong-mode:
|
||||
@@ -7,25 +7,15 @@ analyzer:
|
||||
|
||||
linter:
|
||||
rules:
|
||||
- avoid_types_on_closure_parameters
|
||||
- avoid_void_async
|
||||
- await_only_futures
|
||||
- camel_case_types
|
||||
- cancel_subscriptions
|
||||
- close_sinks
|
||||
- constant_identifier_names
|
||||
- control_flow_in_finally
|
||||
- directives_ordering
|
||||
- empty_statements
|
||||
- hash_and_equals
|
||||
- implementation_imports
|
||||
- non_constant_identifier_names
|
||||
- package_api_docs
|
||||
- package_names
|
||||
- package_prefixed_library_names
|
||||
- test_types_in_equals
|
||||
- throw_in_finally
|
||||
- unnecessary_brace_in_string_interps
|
||||
- unnecessary_getters_setters
|
||||
- unnecessary_new
|
||||
- unnecessary_statements
|
||||
avoid_types_on_closure_parameters: true
|
||||
avoid_void_async: true
|
||||
cancel_subscriptions: true
|
||||
close_sinks: true
|
||||
directives_ordering: true
|
||||
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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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>(
|
||||
|
||||
@@ -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>(
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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'),
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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'),
|
||||
)
|
||||
],
|
||||
),
|
||||
|
||||
@@ -62,11 +62,25 @@ packages:
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_lints:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: flutter_lints
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.3"
|
||||
flutter_test:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
lints:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: lints
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.1"
|
||||
matcher:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -88,13 +102,6 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.8.0"
|
||||
pedantic:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: pedantic
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.9.2"
|
||||
sky_engine:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
|
||||
@@ -15,8 +15,7 @@ dependencies:
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
|
||||
pedantic: ^1.9.0
|
||||
flutter_lints: ^1.0.0
|
||||
|
||||
flutter:
|
||||
uses-material-design: true
|
||||
|
||||
@@ -12,7 +12,8 @@ void main() {
|
||||
var petList = <Map>[];
|
||||
|
||||
setUpAll(() {
|
||||
BasicMessageChannel<dynamic>('jsonMessageCodecDemo', JSONMessageCodec())
|
||||
const BasicMessageChannel<dynamic>(
|
||||
'jsonMessageCodecDemo', JSONMessageCodec())
|
||||
.setMockMessageHandler((dynamic message) async {
|
||||
petList.add(message as Map);
|
||||
});
|
||||
|
||||
@@ -10,7 +10,7 @@ import 'package:platform_channels/src/method_channel_demo.dart';
|
||||
void main() {
|
||||
group('MethodChannelDemo tests', () {
|
||||
setUpAll(() {
|
||||
final methodChannel = MethodChannel('methodChannelDemo');
|
||||
const methodChannel = MethodChannel('methodChannelDemo');
|
||||
|
||||
// Register a mock MethodCallHandler.
|
||||
methodChannel.setMockMethodCallHandler((call) async {
|
||||
|
||||
@@ -12,7 +12,7 @@ import 'package:platform_channels/src/pet_list_screen.dart';
|
||||
|
||||
void main() {
|
||||
group('PetListScreen tests', () {
|
||||
final basicMessageChannel =
|
||||
const basicMessageChannel =
|
||||
BasicMessageChannel('stringCodecDemo', StringCodec());
|
||||
|
||||
var petList = [
|
||||
@@ -33,7 +33,7 @@ void main() {
|
||||
|
||||
// Mock for the index received from the Dart to delete the pet details,
|
||||
// and send the updated pet list back to Dart.
|
||||
BasicMessageChannel('binaryCodecDemo', BinaryCodec())
|
||||
const BasicMessageChannel('binaryCodecDemo', BinaryCodec())
|
||||
.setMockMessageHandler((message) async {
|
||||
// Convert the ByteData to String.
|
||||
final index = utf8.decoder.convert(message.buffer
|
||||
|
||||
@@ -11,7 +11,8 @@ void main() {
|
||||
group('Platform Image Demo tests', () {
|
||||
setUpAll(() {
|
||||
// Register a mock for MessageHandler.
|
||||
BasicMessageChannel<dynamic>('platformImageDemo', StandardMessageCodec())
|
||||
const BasicMessageChannel<dynamic>(
|
||||
'platformImageDemo', StandardMessageCodec())
|
||||
.setMockMessageHandler((dynamic message) async {
|
||||
var byteData = await rootBundle.load('assets/eat_new_orleans.jpg');
|
||||
return byteData.buffer.asUint8List();
|
||||
|
||||
Reference in New Issue
Block a user