1- import 'dart:convert' ;
2-
31import 'package:file/local.dart' ;
42import 'package:file_picker/file_picker.dart' ;
53import 'package:flutter/foundation.dart' ;
64import 'package:flutter/material.dart' ;
75import 'package:flutter/services.dart' ;
86
97class FilePickerDemo extends StatefulWidget {
8+ const FilePickerDemo ({super .key});
9+
1010 @override
11- _FilePickerDemoState createState () => _FilePickerDemoState ();
11+ State < FilePickerDemo > createState () => _FilePickerDemoState ();
1212}
1313
1414class _FilePickerDemoState extends State <FilePickerDemo > {
@@ -36,7 +36,7 @@ class _FilePickerDemoState extends State<FilePickerDemo> {
3636 Icons .error_outline,
3737 ),
3838 contentPadding: EdgeInsets .symmetric (vertical: 40.0 ),
39- title: const Text ('No action taken yet' ),
39+ title: Text ('No action taken yet' ),
4040 subtitle: Text (
4141 'Please use on one of the buttons above to get started' ,
4242 style: TextStyle (
@@ -80,7 +80,7 @@ class _FilePickerDemoState extends State<FilePickerDemo> {
8080 pickedFiles = (await FilePicker .platform.pickFiles (
8181 type: _pickingType,
8282 allowMultiple: _multiPick,
83- onFileLoading: (FilePickerStatus status) => print (status),
83+ onFileLoading: (FilePickerStatus status) => printInDebug (status),
8484 allowedExtensions: (_extension? .isNotEmpty ?? false )
8585 ? _extension? .replaceAll (' ' , '' ).split (',' )
8686 : null ,
@@ -92,7 +92,7 @@ class _FilePickerDemoState extends State<FilePickerDemo> {
9292 ? .files;
9393 hasUserAborted = pickedFiles == null ;
9494 } on PlatformException catch (e) {
95- _logException ('Unsupported operation' + e. toString () );
95+ _logException ('Unsupported operation: $ e ' );
9696 } catch (e) {
9797 _logException (e.toString ());
9898 }
@@ -135,7 +135,7 @@ class _FilePickerDemoState extends State<FilePickerDemo> {
135135 );
136136 hasUserAborted = pickedFilesAndDirectories == null ;
137137 } on PlatformException catch (e) {
138- _logException ('Unsupported operation' + e. toString () );
138+ _logException ('Unsupported operation: $ e ' );
139139 } catch (e) {
140140 _logException (e.toString ());
141141 }
@@ -185,7 +185,7 @@ class _FilePickerDemoState extends State<FilePickerDemo> {
185185 ),
186186 );
187187 } on PlatformException catch (e) {
188- _logException ('Unsupported operation' + e. toString () );
188+ _logException ('Unsupported operation: $ e ' );
189189 } catch (e) {
190190 _logException (e.toString ());
191191 }
@@ -207,7 +207,7 @@ class _FilePickerDemoState extends State<FilePickerDemo> {
207207 );
208208 hasUserAborted = pickedDirectoryPath == null ;
209209 } on PlatformException catch (e) {
210- _logException ('Unsupported operation' + e. toString () );
210+ _logException ('Unsupported operation: $ e ' );
211211 } catch (e) {
212212 _logException (e.toString ());
213213 }
@@ -247,7 +247,7 @@ class _FilePickerDemoState extends State<FilePickerDemo> {
247247 );
248248 hasUserAborted = pickedSaveFilePath == null ;
249249 } on PlatformException catch (e) {
250- _logException ('Unsupported operation' + e. toString () );
250+ _logException ('Unsupported operation: $ e ' );
251251 } catch (e) {
252252 _logException (e.toString ());
253253 }
@@ -269,7 +269,7 @@ class _FilePickerDemoState extends State<FilePickerDemo> {
269269 }
270270
271271 void _logException (String message) {
272- print (message);
272+ printInDebug (message);
273273 _scaffoldMessengerKey.currentState? .hideCurrentSnackBar ();
274274 _scaffoldMessengerKey.currentState? .showSnackBar (
275275 SnackBar (
@@ -373,8 +373,8 @@ class _FilePickerDemoState extends State<FilePickerDemo> {
373373 items: FileType .values
374374 .map (
375375 (fileType) => DropdownMenuItem <FileType >(
376- child: Text (fileType.toString ()),
377376 value: fileType,
377+ child: Text (fileType.toString ()),
378378 ),
379379 )
380380 .toList (),
@@ -569,4 +569,6 @@ class _FilePickerDemoState extends State<FilePickerDemo> {
569569 ),
570570 );
571571 }
572+
573+ void printInDebug (Object object) => debugPrint (object.toString ());
572574}
0 commit comments