diff --git a/CHANGELOG.md b/CHANGELOG.md index 2386e8a..14842e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ #### Web - Add event when canceling the picker. (Thank you @letranloc). +#### Other +- Updates example app to null safety. + ## 3.0.0 Adds null safety support ([#510](https://github.com/miguelpruivo/flutter_file_picker/issues/510)). ## 2.1.7 diff --git a/example/lib/src/file_picker_demo.dart b/example/lib/src/file_picker_demo.dart index dd61119..e86e439 100644 --- a/example/lib/src/file_picker_demo.dart +++ b/example/lib/src/file_picker_demo.dart @@ -9,10 +9,10 @@ class FilePickerDemo extends StatefulWidget { class _FilePickerDemoState extends State { final GlobalKey _scaffoldKey = GlobalKey(); - String _fileName; - List _paths; - String _directoryPath; - String _extension; + String? _fileName; + List? _paths; + String? _directoryPath; + String? _extension; bool _loadingPath = false; bool _multiPick = false; FileType _pickingType = FileType.any; @@ -32,7 +32,7 @@ class _FilePickerDemoState extends State { type: _pickingType, allowMultiple: _multiPick, allowedExtensions: (_extension?.isNotEmpty ?? false) - ? _extension?.replaceAll(' ', '')?.split(',') + ? _extension?.replaceAll(' ', '').split(',') : null, )) ?.files; @@ -44,7 +44,9 @@ class _FilePickerDemoState extends State { if (!mounted) return; setState(() { _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 { FilePicker.platform.clearTemporaryFiles().then((result) { ScaffoldMessenger.of(context).showSnackBar( SnackBar( - backgroundColor: result ? Colors.green : Colors.red, + backgroundColor: result! ? Colors.green : Colors.red, content: Text((result ? 'Temporary files removed with success.' : 'Failed to clean temporary files')), @@ -84,10 +86,10 @@ class _FilePickerDemoState extends State { children: [ Padding( padding: const EdgeInsets.only(top: 20.0), - child: DropdownButton( + child: DropdownButton( hint: const Text('LOAD PATH FROM'), value: _pickingType, - items: [ + items: >[ DropdownMenuItem( child: const Text('FROM AUDIO'), value: FileType.audio, @@ -114,7 +116,7 @@ class _FilePickerDemoState extends State { ), ], onChanged: (value) => setState(() { - _pickingType = value; + _pickingType = value!; if (_pickingType != FileType.custom) { _controller.text = _extension = ''; } @@ -172,7 +174,7 @@ class _FilePickerDemoState extends State { : _directoryPath != null ? ListTile( title: const Text('Directory path'), - subtitle: Text(_directoryPath), + subtitle: Text(_directoryPath!), ) : _paths != null ? Container( @@ -182,20 +184,20 @@ class _FilePickerDemoState extends State { child: Scrollbar( child: ListView.separated( itemCount: - _paths != null && _paths.isNotEmpty - ? _paths.length + _paths != null && _paths!.isNotEmpty + ? _paths!.length : 1, itemBuilder: (BuildContext context, int index) { final bool isMultiPath = - _paths != null && _paths.isNotEmpty; + _paths != null && _paths!.isNotEmpty; final String name = 'File $index: ' + (isMultiPath - ? _paths + ? _paths! .map((e) => e.name) .toList()[index] - : _fileName ?? '...'); - final path = _paths + : _fileName ?? '...')!; + final path = _paths! .map((e) => e.path) .toList()[index] .toString(); diff --git a/example/pubspec.yaml b/example/pubspec.yaml index c3edf91..5f4336d 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -3,7 +3,7 @@ description: An example of how to use the file_picker plugin. version: 1.0.0+1 environment: - sdk: '>=2.10.0 <3.0.0' + sdk: ">=2.12.0 <3.0.0" dependencies: flutter: