flutter_multimedia_picker 1.0.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 80

flutter_multimedia_picker #

Flutter plugin to get All Media.It also allows you to select both images and videos if you wish

Installation #

First, add flutter_multimedia_picker as a dependency in your pubspec.yaml file.

flutter_multimedia_picker: ^1.0.3

Usage #

You need user permission to access media.

  • For IOS: You must to modify the Info.plist file in Runner project
 <key>NSPhotoLibraryUsageDescription</key>
 <string>App need your agree, can visit your meida</string>
  • For Android: You must Add permission to AndroidManifest.xml
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

Example #

  Future<void> getMedia() async {
    try {
      List<MediaFile> imageMediaFileList = await FlutterMultiMediaPicker.getImage();

      List<MediaFile> videoMediaFileList = await FlutterMultiMediaPicker.getVideo();

      List<MediaFile> allMediaFileList = await FlutterMultiMediaPicker.getAll();

      if (imageMediaFileList.length > 0) {
        MediaFile imageMedia = await FlutterMultiMediaPicker.getMediaFile(
            fileId: imageMediaFileList[0].id, type: MediaType.IMAGE);
      }

      if (videoMediaFileList.length > 0) {
        MediaFile videoMedia = await FlutterMultiMediaPicker.getMediaFile(
            fileId: videoMediaFileList[0].id, type: MediaType.VIDEO);
      }

      if (imageMediaFileList.length > 0) {
        String imageMedia = await FlutterMultiMediaPicker.getThumbnail(
            fileId: imageMediaFileList[0].id, type: MediaType.IMAGE);
      }

      if (videoMediaFileList.length > 0) {
        String videoMedia = await FlutterMultiMediaPicker.getThumbnail(
            fileId: videoMediaFileList[0].id, type: MediaType.VIDEO);
      }
    } on Exception {
      print("Exception");
    }
  }

Credits #

Thanks to Kasem SAEED for his awesome media_picker_builder library. It's the core of this library.

1.0.0 #

  • Initial release

1.0.1 #

  • Example Added

1.0.2 #

  • Full Example Added

1.0.3 #

  • Swift Version Added

example/lib/main.dart

import 'dart:io';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter_multimedia_picker/fullter_multimedia_picker.dart';
import 'package:flutter_multimedia_picker/data/MediaFile.dart';
import 'package:flutter_multimedia_picker/widget/PickerWidget.dart';
import 'package:permission_handler/permission_handler.dart';

void main() =>
    runApp(MaterialApp(
      title: "App",
      home: MyApp(),
    ));

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String selectText = "";

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

    _checkPermission().then((granted) {
      if (!granted) return;
    });
  }

  Future<bool> _checkPermission() async {
    final permissionStorageGroup =
    Platform.isIOS ? PermissionGroup.photos : PermissionGroup.storage;
    Map<PermissionGroup, PermissionStatus> res =
    await PermissionHandler().requestPermissions([
      permissionStorageGroup,
    ]);
    return res[permissionStorageGroup] == PermissionStatus.granted;
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> getMedia() async {
    try {
      List<MediaFile> imageMediaFileList =
      await FlutterMultiMediaPicker.getImage();

      List<MediaFile> videoMediaFileList =
      await FlutterMultiMediaPicker.getVideo();

      List<MediaFile> allMediaFileList = await FlutterMultiMediaPicker.getAll();

      if (imageMediaFileList.length > 0) {
        MediaFile imageMedia = await FlutterMultiMediaPicker.getMediaFile(
            fileId: imageMediaFileList[0].id, type: MediaType.IMAGE);
      }

      if (videoMediaFileList.length > 0) {
        MediaFile videoMedia = await FlutterMultiMediaPicker.getMediaFile(
            fileId: videoMediaFileList[0].id, type: MediaType.VIDEO);
      }

      if (imageMediaFileList.length > 0) {
        String imageMedia = await FlutterMultiMediaPicker.getThumbnail(
            fileId: imageMediaFileList[0].id, type: MediaType.IMAGE);
      }

      if (videoMediaFileList.length > 0) {
        String videoMedia = await FlutterMultiMediaPicker.getThumbnail(
            fileId: videoMediaFileList[0].id, type: MediaType.VIDEO);
      }
    } on Exception {
      print("Exception");
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Plugin example app'),
      ),
      body: Center(
        child: Column(
          children: <Widget>[
            RaisedButton(
                child: const Text("Show All Media"),
                onPressed: () {
                  FlutterMultiMediaPicker.getAll().then((mediaFiles) {
                    //print(mediaFiles);
                    _awaitReturnValueFromSecondScreen(context, mediaFiles);
                  });
                }),
            RaisedButton(
                child: const Text("Show Image Media"),
                onPressed: () {
                  FlutterMultiMediaPicker.getImage().then((mediaFiles) {
                    //print(mediaFiles);
                    _awaitReturnValueFromSecondScreen(context, mediaFiles);
                  });
                }),
            RaisedButton(
                child: const Text("Show Video Media"),
                onPressed: () {
                  FlutterMultiMediaPicker.getVideo().then((mediaFiles) {
                    //print(mediaFiles);
                    _awaitReturnValueFromSecondScreen(context, mediaFiles);
                  });
                }),
            Text("$selectText")
          ],
        ),
      ),
    );
  }

  void _awaitReturnValueFromSecondScreen(BuildContext context,
      List<MediaFile> mediaFiles) async {
    // start the SecondScreen and wait for it to finish with a result
    Set<MediaFile> result = await Navigator.push(
        context,
        MaterialPageRoute(
          builder: (context) => PickerScreen(mediaFiles),
        ));

    // after the SecondScreen result comes back update the Text widget with it

    if (result == null) {
      return;
    }

    setState(() {
      int size = result.length;
      selectText = "Selected Media Size $size";
    });
  }
}


class PickerScreen extends StatefulWidget {

  List<MediaFile> mediaFiles;

  PickerScreen(this.mediaFiles);

  @override
  _PickerScreenState createState() => _PickerScreenState();
}

class _PickerScreenState extends State<PickerScreen> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text("Media Picker"),
        ),
        body: Center(
          child: PickerWidget(widget.mediaFiles, onDone, onCancel),
        ));
  }

  onDone(Set<MediaFile> selectedFiles) {
    Navigator.pop(context, selectedFiles);
  }

  onCancel() {
    Navigator.pop(context);
  }

}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_multimedia_picker: ^1.0.3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_multimedia_picker/data/MediaFile.dart';
import 'package:flutter_multimedia_picker/fullter_multimedia_picker.dart';
import 'package:flutter_multimedia_picker/widget/GalleryWidget.dart';
import 'package:flutter_multimedia_picker/widget/GalleryWidgetItem.dart';
import 'package:flutter_multimedia_picker/widget/MultiSelectorModel.dart';
import 'package:flutter_multimedia_picker/widget/PickerWidget.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
67
Health:
Code health derived from static analysis. [more]
95
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
80
Learn more about scoring.

We analyzed this package on Apr 4, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health issues and suggestions

Fix lib/widget/PickerWidget.dart. (-5.48 points)

Analysis of lib/widget/PickerWidget.dart reported 1 warning, 1 hint:

line 33 col 12: The parameter 'create' is required. .

line 34 col 7: 'builder' is deprecated and shouldn't be used. will be removed in 4.0.0, use create instead.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (provider).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
provider ^3.1.0+1 3.2.0 4.0.4
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test