Skip to content

Commit 1ef4405

Browse files
[file_selector] Remove custom analysis options (flutter#4382)
Switches to the new repo-standard analysis options, and fixes all violations. Part of flutter#76229
1 parent f63395d commit 1ef4405

27 files changed

+321
-277
lines changed

packages/file_selector/analysis_options.yaml

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/file_selector/file_selector/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## NEXT
2+
3+
* Minor code cleanup for new analysis rules.
4+
15
## 0.8.2
26

37
* Update platform_plugin_interface version requirement.

packages/file_selector/file_selector/example/lib/get_directory_page.dart

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,26 @@ import 'package:flutter/material.dart';
77

88
/// Screen that shows an example of getDirectoryPath
99
class GetDirectoryPage extends StatelessWidget {
10-
void _getDirectoryPath(BuildContext context) async {
11-
final String confirmButtonText = 'Choose';
10+
Future<void> _getDirectoryPath(BuildContext context) async {
11+
const String confirmButtonText = 'Choose';
1212
final String? directoryPath = await getDirectoryPath(
1313
confirmButtonText: confirmButtonText,
1414
);
1515
if (directoryPath == null) {
1616
// Operation was canceled by the user.
1717
return;
1818
}
19-
await showDialog(
19+
await showDialog<void>(
2020
context: context,
21-
builder: (context) => TextDisplay(directoryPath),
21+
builder: (BuildContext context) => TextDisplay(directoryPath),
2222
);
2323
}
2424

2525
@override
2626
Widget build(BuildContext context) {
2727
return Scaffold(
2828
appBar: AppBar(
29-
title: Text("Open a text file"),
29+
title: const Text('Open a text file'),
3030
),
3131
body: Center(
3232
child: Column(
@@ -37,7 +37,7 @@ class GetDirectoryPage extends StatelessWidget {
3737
primary: Colors.blue,
3838
onPrimary: Colors.white,
3939
),
40-
child: Text('Press to ask user to choose a directory'),
40+
child: const Text('Press to ask user to choose a directory'),
4141
onPressed: () => _getDirectoryPath(context),
4242
),
4343
],
@@ -49,22 +49,22 @@ class GetDirectoryPage extends StatelessWidget {
4949

5050
/// Widget that displays a text file in a dialog
5151
class TextDisplay extends StatelessWidget {
52+
/// Default Constructor
53+
const TextDisplay(this.directoryPath);
54+
5255
/// Directory path
5356
final String directoryPath;
5457

55-
/// Default Constructor
56-
TextDisplay(this.directoryPath);
57-
5858
@override
5959
Widget build(BuildContext context) {
6060
return AlertDialog(
61-
title: Text('Selected Directory'),
61+
title: const Text('Selected Directory'),
6262
content: Scrollbar(
6363
child: SingleChildScrollView(
6464
child: Text(directoryPath),
6565
),
6666
),
67-
actions: [
67+
actions: <Widget>[
6868
TextButton(
6969
child: const Text('Close'),
7070
onPressed: () => Navigator.pop(context),

packages/file_selector/file_selector/example/lib/home_page.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,39 @@ class HomePage extends StatelessWidget {
1414
);
1515
return Scaffold(
1616
appBar: AppBar(
17-
title: Text('File Selector Demo Home Page'),
17+
title: const Text('File Selector Demo Home Page'),
1818
),
1919
body: Center(
2020
child: Column(
2121
mainAxisAlignment: MainAxisAlignment.center,
2222
children: <Widget>[
2323
ElevatedButton(
2424
style: style,
25-
child: Text('Open a text file'),
25+
child: const Text('Open a text file'),
2626
onPressed: () => Navigator.pushNamed(context, '/open/text'),
2727
),
28-
SizedBox(height: 10),
28+
const SizedBox(height: 10),
2929
ElevatedButton(
3030
style: style,
31-
child: Text('Open an image'),
31+
child: const Text('Open an image'),
3232
onPressed: () => Navigator.pushNamed(context, '/open/image'),
3333
),
34-
SizedBox(height: 10),
34+
const SizedBox(height: 10),
3535
ElevatedButton(
3636
style: style,
37-
child: Text('Open multiple images'),
37+
child: const Text('Open multiple images'),
3838
onPressed: () => Navigator.pushNamed(context, '/open/images'),
3939
),
40-
SizedBox(height: 10),
40+
const SizedBox(height: 10),
4141
ElevatedButton(
4242
style: style,
43-
child: Text('Save a file'),
43+
child: const Text('Save a file'),
4444
onPressed: () => Navigator.pushNamed(context, '/save/text'),
4545
),
46-
SizedBox(height: 10),
46+
const SizedBox(height: 10),
4747
ElevatedButton(
4848
style: style,
49-
child: Text('Open a get directory dialog'),
49+
child: const Text('Open a get directory dialog'),
5050
onPressed: () => Navigator.pushNamed(context, '/directory'),
5151
),
5252
],

packages/file_selector/file_selector/example/lib/main.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import 'package:flutter/material.dart';
6-
import 'package:example/home_page.dart';
75
import 'package:example/get_directory_page.dart';
8-
import 'package:example/open_text_page.dart';
6+
import 'package:example/home_page.dart';
97
import 'package:example/open_image_page.dart';
108
import 'package:example/open_multiple_images_page.dart';
9+
import 'package:example/open_text_page.dart';
1110
import 'package:example/save_text_page.dart';
11+
import 'package:flutter/material.dart';
1212

1313
void main() {
1414
runApp(MyApp());
@@ -25,12 +25,12 @@ class MyApp extends StatelessWidget {
2525
visualDensity: VisualDensity.adaptivePlatformDensity,
2626
),
2727
home: HomePage(),
28-
routes: {
29-
'/open/image': (context) => OpenImagePage(),
30-
'/open/images': (context) => OpenMultipleImagesPage(),
31-
'/open/text': (context) => OpenTextPage(),
32-
'/save/text': (context) => SaveTextPage(),
33-
'/directory': (context) => GetDirectoryPage(),
28+
routes: <String, WidgetBuilder>{
29+
'/open/image': (BuildContext context) => OpenImagePage(),
30+
'/open/images': (BuildContext context) => OpenMultipleImagesPage(),
31+
'/open/text': (BuildContext context) => OpenTextPage(),
32+
'/save/text': (BuildContext context) => SaveTextPage(),
33+
'/directory': (BuildContext context) => GetDirectoryPage(),
3434
},
3535
);
3636
}

packages/file_selector/file_selector/example/lib/open_image_page.dart

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@
33
// found in the LICENSE file.
44

55
import 'dart:io';
6-
import 'package:flutter/foundation.dart';
6+
77
import 'package:file_selector/file_selector.dart';
8+
import 'package:flutter/foundation.dart';
89
import 'package:flutter/material.dart';
910

1011
/// Screen that shows an example of openFiles
1112
class OpenImagePage extends StatelessWidget {
12-
void _openImageFile(BuildContext context) async {
13+
Future<void> _openImageFile(BuildContext context) async {
1314
final XTypeGroup typeGroup = XTypeGroup(
1415
label: 'images',
15-
extensions: ['jpg', 'png'],
16+
extensions: <String>['jpg', 'png'],
1617
);
17-
final List<XFile> files = await openFiles(acceptedTypeGroups: [typeGroup]);
18+
final List<XFile> files =
19+
await openFiles(acceptedTypeGroups: <XTypeGroup>[typeGroup]);
1820
if (files.isEmpty) {
1921
// Operation was canceled by the user.
2022
return;
@@ -23,17 +25,17 @@ class OpenImagePage extends StatelessWidget {
2325
final String fileName = file.name;
2426
final String filePath = file.path;
2527

26-
await showDialog(
28+
await showDialog<void>(
2729
context: context,
28-
builder: (context) => ImageDisplay(fileName, filePath),
30+
builder: (BuildContext context) => ImageDisplay(fileName, filePath),
2931
);
3032
}
3133

3234
@override
3335
Widget build(BuildContext context) {
3436
return Scaffold(
3537
appBar: AppBar(
36-
title: Text("Open an image"),
38+
title: const Text('Open an image'),
3739
),
3840
body: Center(
3941
child: Column(
@@ -44,7 +46,7 @@ class OpenImagePage extends StatelessWidget {
4446
primary: Colors.blue,
4547
onPrimary: Colors.white,
4648
),
47-
child: Text('Press to open an image file(png, jpg)'),
49+
child: const Text('Press to open an image file(png, jpg)'),
4850
onPressed: () => _openImageFile(context),
4951
),
5052
],
@@ -56,23 +58,23 @@ class OpenImagePage extends StatelessWidget {
5658

5759
/// Widget that displays a text file in a dialog
5860
class ImageDisplay extends StatelessWidget {
61+
/// Default Constructor
62+
const ImageDisplay(this.fileName, this.filePath);
63+
5964
/// Image's name
6065
final String fileName;
6166

6267
/// Image's path
6368
final String filePath;
6469

65-
/// Default Constructor
66-
ImageDisplay(this.fileName, this.filePath);
67-
6870
@override
6971
Widget build(BuildContext context) {
7072
return AlertDialog(
7173
title: Text(fileName),
7274
// On web the filePath is a blob url
7375
// while on other platforms it is a system path.
7476
content: kIsWeb ? Image.network(filePath) : Image.file(File(filePath)),
75-
actions: [
77+
actions: <Widget>[
7678
TextButton(
7779
child: const Text('Close'),
7880
onPressed: () {

packages/file_selector/file_selector/example/lib/open_multiple_images_page.dart

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,41 @@
33
// found in the LICENSE file.
44

55
import 'dart:io';
6-
import 'package:flutter/foundation.dart';
6+
77
import 'package:file_selector/file_selector.dart';
8+
import 'package:flutter/foundation.dart';
89
import 'package:flutter/material.dart';
910

1011
/// Screen that shows an example of openFiles
1112
class OpenMultipleImagesPage extends StatelessWidget {
12-
void _openImageFile(BuildContext context) async {
13+
Future<void> _openImageFile(BuildContext context) async {
1314
final XTypeGroup jpgsTypeGroup = XTypeGroup(
1415
label: 'JPEGs',
15-
extensions: ['jpg', 'jpeg'],
16+
extensions: <String>['jpg', 'jpeg'],
1617
);
1718
final XTypeGroup pngTypeGroup = XTypeGroup(
1819
label: 'PNGs',
19-
extensions: ['png'],
20+
extensions: <String>['png'],
2021
);
21-
final List<XFile> files = await openFiles(acceptedTypeGroups: [
22+
final List<XFile> files = await openFiles(acceptedTypeGroups: <XTypeGroup>[
2223
jpgsTypeGroup,
2324
pngTypeGroup,
2425
]);
2526
if (files.isEmpty) {
2627
// Operation was canceled by the user.
2728
return;
2829
}
29-
await showDialog(
30+
await showDialog<void>(
3031
context: context,
31-
builder: (context) => MultipleImagesDisplay(files),
32+
builder: (BuildContext context) => MultipleImagesDisplay(files),
3233
);
3334
}
3435

3536
@override
3637
Widget build(BuildContext context) {
3738
return Scaffold(
3839
appBar: AppBar(
39-
title: Text("Open multiple images"),
40+
title: const Text('Open multiple images'),
4041
),
4142
body: Center(
4243
child: Column(
@@ -47,7 +48,7 @@ class OpenMultipleImagesPage extends StatelessWidget {
4748
primary: Colors.blue,
4849
onPrimary: Colors.white,
4950
),
50-
child: Text('Press to open multiple images (png, jpg)'),
51+
child: const Text('Press to open multiple images (png, jpg)'),
5152
onPressed: () => _openImageFile(context),
5253
),
5354
],
@@ -59,31 +60,31 @@ class OpenMultipleImagesPage extends StatelessWidget {
5960

6061
/// Widget that displays a text file in a dialog
6162
class MultipleImagesDisplay extends StatelessWidget {
63+
/// Default Constructor
64+
const MultipleImagesDisplay(this.files);
65+
6266
/// The files containing the images
6367
final List<XFile> files;
6468

65-
/// Default Constructor
66-
MultipleImagesDisplay(this.files);
67-
6869
@override
6970
Widget build(BuildContext context) {
7071
return AlertDialog(
71-
title: Text('Gallery'),
72+
title: const Text('Gallery'),
7273
// On web the filePath is a blob url
7374
// while on other platforms it is a system path.
7475
content: Center(
7576
child: Row(
7677
children: <Widget>[
7778
...files.map(
78-
(file) => Flexible(
79+
(XFile file) => Flexible(
7980
child: kIsWeb
8081
? Image.network(file.path)
8182
: Image.file(File(file.path))),
8283
)
8384
],
8485
),
8586
),
86-
actions: [
87+
actions: <Widget>[
8788
TextButton(
8889
child: const Text('Close'),
8990
onPressed: () {

0 commit comments

Comments
 (0)