Updates example app to null safety
This commit is contained in:
parent
911ba7be18
commit
74289af412
|
@ -5,6 +5,9 @@
|
||||||
#### Web
|
#### Web
|
||||||
- Add event when canceling the picker. (Thank you @letranloc).
|
- Add event when canceling the picker. (Thank you @letranloc).
|
||||||
|
|
||||||
|
#### Other
|
||||||
|
- Updates example app to null safety.
|
||||||
|
|
||||||
## 3.0.0
|
## 3.0.0
|
||||||
Adds null safety support ([#510](https://github.com/miguelpruivo/flutter_file_picker/issues/510)).
|
Adds null safety support ([#510](https://github.com/miguelpruivo/flutter_file_picker/issues/510)).
|
||||||
## 2.1.7
|
## 2.1.7
|
||||||
|
|
|
@ -9,10 +9,10 @@ class FilePickerDemo extends StatefulWidget {
|
||||||
|
|
||||||
class _FilePickerDemoState extends State<FilePickerDemo> {
|
class _FilePickerDemoState extends State<FilePickerDemo> {
|
||||||
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
||||||
String _fileName;
|
String? _fileName;
|
||||||
List<PlatformFile> _paths;
|
List<PlatformFile>? _paths;
|
||||||
String _directoryPath;
|
String? _directoryPath;
|
||||||
String _extension;
|
String? _extension;
|
||||||
bool _loadingPath = false;
|
bool _loadingPath = false;
|
||||||
bool _multiPick = false;
|
bool _multiPick = false;
|
||||||
FileType _pickingType = FileType.any;
|
FileType _pickingType = FileType.any;
|
||||||
|
@ -32,7 +32,7 @@ class _FilePickerDemoState extends State<FilePickerDemo> {
|
||||||
type: _pickingType,
|
type: _pickingType,
|
||||||
allowMultiple: _multiPick,
|
allowMultiple: _multiPick,
|
||||||
allowedExtensions: (_extension?.isNotEmpty ?? false)
|
allowedExtensions: (_extension?.isNotEmpty ?? false)
|
||||||
? _extension?.replaceAll(' ', '')?.split(',')
|
? _extension?.replaceAll(' ', '').split(',')
|
||||||
: null,
|
: null,
|
||||||
))
|
))
|
||||||
?.files;
|
?.files;
|
||||||
|
@ -44,7 +44,9 @@ class _FilePickerDemoState extends State<FilePickerDemo> {
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
setState(() {
|
setState(() {
|
||||||
_loadingPath = false;
|
_loadingPath = false;
|
||||||
_fileName = _paths != null ? _paths.map((e) => e.name).toString() : '...';
|
print(_paths!.first.extension);
|
||||||
|
_fileName =
|
||||||
|
_paths != null ? _paths!.map((e) => e.name).toString() : '...';
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +54,7 @@ class _FilePickerDemoState extends State<FilePickerDemo> {
|
||||||
FilePicker.platform.clearTemporaryFiles().then((result) {
|
FilePicker.platform.clearTemporaryFiles().then((result) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
backgroundColor: result ? Colors.green : Colors.red,
|
backgroundColor: result! ? Colors.green : Colors.red,
|
||||||
content: Text((result
|
content: Text((result
|
||||||
? 'Temporary files removed with success.'
|
? 'Temporary files removed with success.'
|
||||||
: 'Failed to clean temporary files')),
|
: 'Failed to clean temporary files')),
|
||||||
|
@ -84,10 +86,10 @@ class _FilePickerDemoState extends State<FilePickerDemo> {
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(top: 20.0),
|
padding: const EdgeInsets.only(top: 20.0),
|
||||||
child: DropdownButton(
|
child: DropdownButton<FileType>(
|
||||||
hint: const Text('LOAD PATH FROM'),
|
hint: const Text('LOAD PATH FROM'),
|
||||||
value: _pickingType,
|
value: _pickingType,
|
||||||
items: <DropdownMenuItem>[
|
items: <DropdownMenuItem<FileType>>[
|
||||||
DropdownMenuItem(
|
DropdownMenuItem(
|
||||||
child: const Text('FROM AUDIO'),
|
child: const Text('FROM AUDIO'),
|
||||||
value: FileType.audio,
|
value: FileType.audio,
|
||||||
|
@ -114,7 +116,7 @@ class _FilePickerDemoState extends State<FilePickerDemo> {
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
onChanged: (value) => setState(() {
|
onChanged: (value) => setState(() {
|
||||||
_pickingType = value;
|
_pickingType = value!;
|
||||||
if (_pickingType != FileType.custom) {
|
if (_pickingType != FileType.custom) {
|
||||||
_controller.text = _extension = '';
|
_controller.text = _extension = '';
|
||||||
}
|
}
|
||||||
|
@ -172,7 +174,7 @@ class _FilePickerDemoState extends State<FilePickerDemo> {
|
||||||
: _directoryPath != null
|
: _directoryPath != null
|
||||||
? ListTile(
|
? ListTile(
|
||||||
title: const Text('Directory path'),
|
title: const Text('Directory path'),
|
||||||
subtitle: Text(_directoryPath),
|
subtitle: Text(_directoryPath!),
|
||||||
)
|
)
|
||||||
: _paths != null
|
: _paths != null
|
||||||
? Container(
|
? Container(
|
||||||
|
@ -182,20 +184,20 @@ class _FilePickerDemoState extends State<FilePickerDemo> {
|
||||||
child: Scrollbar(
|
child: Scrollbar(
|
||||||
child: ListView.separated(
|
child: ListView.separated(
|
||||||
itemCount:
|
itemCount:
|
||||||
_paths != null && _paths.isNotEmpty
|
_paths != null && _paths!.isNotEmpty
|
||||||
? _paths.length
|
? _paths!.length
|
||||||
: 1,
|
: 1,
|
||||||
itemBuilder:
|
itemBuilder:
|
||||||
(BuildContext context, int index) {
|
(BuildContext context, int index) {
|
||||||
final bool isMultiPath =
|
final bool isMultiPath =
|
||||||
_paths != null && _paths.isNotEmpty;
|
_paths != null && _paths!.isNotEmpty;
|
||||||
final String name = 'File $index: ' +
|
final String name = 'File $index: ' +
|
||||||
(isMultiPath
|
(isMultiPath
|
||||||
? _paths
|
? _paths!
|
||||||
.map((e) => e.name)
|
.map((e) => e.name)
|
||||||
.toList()[index]
|
.toList()[index]
|
||||||
: _fileName ?? '...');
|
: _fileName ?? '...')!;
|
||||||
final path = _paths
|
final path = _paths!
|
||||||
.map((e) => e.path)
|
.map((e) => e.path)
|
||||||
.toList()[index]
|
.toList()[index]
|
||||||
.toString();
|
.toString();
|
||||||
|
|
|
@ -3,7 +3,7 @@ description: An example of how to use the file_picker plugin.
|
||||||
version: 1.0.0+1
|
version: 1.0.0+1
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=2.10.0 <3.0.0'
|
sdk: ">=2.12.0 <3.0.0"
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
flutter:
|
flutter:
|
||||||
|
|
Loading…
Reference in New Issue