### Initialize File Picker Demo Source: https://pub.dev/packages/file_picker/example This is the main entry point for the file picker example application. It initializes the FilePickerDemo widget. ```dart import 'package:file_picker_example/src/file_picker_demo.dart'; import 'package:flutter/widgets.dart'; void main() => runApp(FilePickerDemo()); ``` -------------------------------- ### Pubspec.yaml Dependency Source: https://pub.dev/packages/file_picker/install This is an example of how the file_picker dependency will appear in your pubspec.yaml file after running the add command. ```yaml dependencies: file_picker: ^11.0.2 ``` -------------------------------- ### Upload File to Firebase Storage (Web) Source: https://pub.dev/packages/file_picker Example of picking a file and uploading its bytes to Firebase Storage using Flutter Web. Requires Firebase Storage SDK setup. ```dart FilePickerResult? result = await FilePicker.pickFiles(); if (result != null) { Uint8List fileBytes = result.files.first.bytes; String fileName = result.files.first.name; // Upload file await FirebaseStorage.instance.ref('uploads/$fileName').putData(fileBytes); } ``` -------------------------------- ### Pick Directory Path Source: https://pub.dev/packages/file_picker Use this method to allow users to select a directory. Returns null if the user cancels. ```dart String? selectedDirectory = await FilePicker.getDirectoryPath(); if (selectedDirectory == null) { // User canceled the picker } ``` -------------------------------- ### Load File Details Source: https://pub.dev/packages/file_picker Retrieves details of the picked file, including name, bytes, size, extension, and path. The 'bytes' property is useful for immediate data handling. ```dart FilePickerResult? result = await FilePicker.pickFiles(); if (result != null) { PlatformFile file = result.files.first; print(file.name); print(file.bytes); print(file.size); print(file.extension); print(file.path); } else { // User canceled the picker } ``` -------------------------------- ### Retrieve Files as XFiles Source: https://pub.dev/packages/file_picker Demonstrates how to access picked files as XFile objects, which can be used with other Flutter libraries. Both a list of all XFiles and individual XFiles are accessible. ```dart FilePickerResult? result = await FilePicker.pickFiles(); if (result != null) { // All files List xFiles = result.xFiles; // Individually XFile xFile = result.files.first.xFile; } else { // User canceled the picker } ``` -------------------------------- ### Pick Multiple Files Source: https://pub.dev/packages/file_picker Allows users to select multiple files. The result.paths provides a list of selected file paths. ```dart FilePickerResult? result = await FilePicker.pickFiles(allowMultiple: true); if (result != null) { List files = result.paths.map((path) => File(path!)).toList(); } else { // User canceled the picker } ``` -------------------------------- ### Pick Single File Source: https://pub.dev/packages/file_picker Use this to pick a single file. The result can be null if the user cancels the picker. ```dart FilePickerResult? result = await FilePicker.pickFiles(); if (result != null) { File file = File(result.files.single.path!); } else { // User canceled the picker } ``` -------------------------------- ### Save File Dialog Source: https://pub.dev/packages/file_picker Opens a save-file/save-as dialog, allowing the user to specify the output file name and location. Returns the selected path or null if canceled. ```dart String? outputFile = await FilePicker.saveFile( dialogTitle: 'Please select an output file:', fileName: 'output-file.pdf', ); if (outputFile == null) { // User canceled the picker } ``` -------------------------------- ### Pick Files with Extension Filter Source: https://pub.dev/packages/file_picker Enables filtering files by a custom list of extensions. Ensure 'FileType.custom' is set for custom filtering. ```dart FilePickerResult? result = await FilePicker.pickFiles( allowMultiple: true, type: FileType.custom, allowedExtensions: ['jpg', 'pdf', 'doc'], ); ``` -------------------------------- ### Add file_picker Dependency Source: https://pub.dev/packages/file_picker/install Run this command in your terminal to add the file_picker package to your Flutter project. This command automatically updates your pubspec.yaml file. ```bash flutter pub add file_picker ``` -------------------------------- ### Import file_picker in Dart Source: https://pub.dev/packages/file_picker/install Include this import statement at the top of your Dart files to use the functionality provided by the file_picker package. ```dart import 'package:file_picker/file_picker.dart'; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.