ma_file_picker_plus 0.0.6 copy "ma_file_picker_plus: ^0.0.6" to clipboard
ma_file_picker_plus: ^0.0.6 copied to clipboard

PlatformAndroidiOS
unlisted

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'),
        ),
      ),
    );
  }
}
0
likes
125
points
6
downloads

Publisher

unverified uploader

Weekly Downloads

Mariapps Internal Package to build Flutter apps faster

Repository (GitHub)

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

file_picker, flutter, flutter_svg, fpdart, image_picker, mariapps_utils, path, plugin_platform_interface

More

Packages that depend on ma_file_picker_plus

Packages that implement ma_file_picker_plus