ma_file_picker_plus 0.0.6
ma_file_picker_plus: ^0.0.6 copied to clipboard
Mariapps Internal Package to build Flutter apps faster
example/lib/main.dart
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:ma_file_picker_plus/file_picker_plus.dart';
import 'package:path_provider/path_provider.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
// β
The MaterialApp is at the root now
return const MaterialApp(
title: 'File Picker Example',
home: FilePickerHome(), // π Move Scaffold here
);
}
}
class FilePickerHome extends StatefulWidget {
const FilePickerHome({super.key});
@override
State<FilePickerHome> createState() => _FilePickerHomeState();
}
class _FilePickerHomeState extends State<FilePickerHome> {
String? path;
@override
initState() {
super.initState();
_initPath();
}
Future<void> _initPath() async {
final dir = await getApplicationDocumentsDirectory();
setState(() {
path = dir.path;
});
}
@override
Widget build(BuildContext context) {
// β
This context is now inside MaterialApp
return Scaffold(
appBar: AppBar(title: const Text('File Picker Example')),
body: Center(
child: ElevatedButton(
onPressed: () async {
final file = await FilePickerPlus.pick(
context: context, // β
valid context now
allowDocuments: true,
directory: path
);
if (file != null) {
if (kDebugMode) {
print('Picked file: ${file.path}');
}
} else {
if (kDebugMode) {
print('No file selected');
}
}
},
child: const Text('Pick File'),
),
),
);
}
}