plux_media_picker 1.0.0 copy "plux_media_picker: ^1.0.0" to clipboard
plux_media_picker: ^1.0.0 copied to clipboard

A Flutter plugin that provides a unified API to pick photos, videos, and files from the device's gallery, camera, and file system.

example/lib/main.dart

import 'dart:io';

import 'package:plux_media_picker/plux_media_picker.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final _pluxMediaPickerPlugin = PluxMediaPicker();

  final List<File> selectedMedia = [];
  final List<File> selectedFiles = [];

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Plugin example app')),
        body: Center(
          child: Column(
            children: [
              Row(
                children: selectedMedia
                    .map(
                      (file) => Expanded(
                        child: Column(
                          spacing: 10,
                          mainAxisSize: MainAxisSize.min,
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            Image.file(file, width: 100, height: 100, fit: BoxFit.cover),
                            Text("SIZE: ${file.lengthSync()}"),
                            Text(file.path.split('/').last),
                            Text(file.path),
                          ],
                        ),
                      ),
                    )
                    .toList(),
              ),

              Row(
                children: selectedFiles
                    .map(
                      (file) => Expanded(
                        child: Column(
                          spacing: 10,
                          mainAxisSize: MainAxisSize.min,
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            Text("SIZE: ${file.lengthSync()}"),
                            Text(file.path.split('/').last),
                            Text(file.path),
                          ],
                        ),
                      ),
                    )
                    .toList(),
              ),
              ElevatedButton(
                onPressed: () async {
                  try {
                    File? result = await _pluxMediaPickerPlugin.pickCamera(mediaType: CameraMediaType.image);
                    if (result != null) {
                      selectedMedia.add(result);
                    }
                  } on PluxMediaPickerException catch (ex) {
                    debugPrint(ex.description);
                  } catch (ex) {
                    debugPrint(ex.toString());
                  }
                  setState(() {});
                },
                child: const Text('Pick from Camera'),
              ),

              ElevatedButton(
                onPressed: () async {
                  try {
                    final savedRes = await _pluxMediaPickerPlugin.getLostFiles();
                    if (savedRes.isEmpty) {
                      List<File> result = await _pluxMediaPickerPlugin.pickGallery(maxLimit: 10, quality: 0.8);
                      selectedMedia.addAll(result);
                    } else {
                      selectedMedia.addAll(savedRes);
                    }
                  } catch (ex) {
                    debugPrint(ex.toString());
                  }

                  setState(() {});
                },
                child: const Text('Pick from Gallery'),
              ),

              ElevatedButton(
                onPressed: () async {
                  try {
                    final result = await _pluxMediaPickerPlugin.pickFiles(multipleSelection: true, allowedExtensions: ['docx', 'png']);
                    selectedFiles.addAll(result);
                  } catch (ex) {
                    debugPrint(ex.toString());
                  }

                  setState(() {});
                },
                child: const Text('Pick from files'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
0
likes
0
points
20
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin that provides a unified API to pick photos, videos, and files from the device's gallery, camera, and file system.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, meta, pigeon, plugin_platform_interface

More

Packages that depend on plux_media_picker

Packages that implement plux_media_picker