gmo_media_picker

Flutter plugin to get pictures, videos and audios. It allows you to select one or more images from gallery or camera, without needing to switch provider. It also allows you to select both images, videos and audios if you wish

Requirements

Android

Kotlin and Gradle version

  • Upgrade your Gradle version (the one in gradle-wrapper.properties) to 6.8.3 or the latest version but lower than 7.0.0.
  • Upgrade your Kotlin version (ext.kotlin_version) to 1.4.32 or the latest version.
  • Required permissions: INTERNET, READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE, ACCESS_MEDIA_LOCATION. If you don't need the ACCESS_MEDIA_LOCATION permission,
<uses-permission
  android:name="android.permission.ACCESS_MEDIA_LOCATION"
  tools:node="remove"
  />

iOS

  1. Platform version has to be at least 10.0. Modify ios/Podfile and update accordingly.
platform :ios, '10.0'
  1. Add the following content to info.plist.
<key>NSAppTransportSecurity</key>
<dict>
	<key>NSAllowsArbitraryLoads</key>
	<true/>
</dict>
<key>NSPhotoLibraryUsageDescription</key>
<string>Replace with your permission description.</string>

install

Add to pubspec

dependencies:
  gmo_media_picker: 0.0.1

Screenshots

123

Usage

import 'package:media_picker/media_picker.dart';
 MediaPicker.assetPicker(
      context,
      singleCallback: (AssetEntity asset){
        //return selected items
      }
  );
ParameterTypeDescriptionDefault
isMultiboolMultiple select modefalse
typeRequestTypeRequest type for pickerRequestType.common
limitintMaximum asset that the picker can pick10
isReviewboolReview before selecttrue
filterOptionsFilterOptionGroup?Allow users to customize assets filter optionsnull
leadingBuilderWidgetBuilder?The widget builder for the special itemnull
routeDurationDurationThe duration which the picker use to build page route transitionconst Duration(milliseconds: 300)
mulCallbackMulCallback?Return list item in selectnull
singleCallbackSingleCallback?Return item in selectnull

Example


import 'package:gmo_media_picker/media_picker.dart';

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);
  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  bool isReview = false;
  bool isMulti = false;
  @override
  Widget build(BuildContext context) {
    final themeData = Theme.of(context);
    return Scaffold(
      appBar: AppBar(
        title:const  Text('Media picker example'),
      ),
      body: SafeArea(
        child: SizedBox(
          width: double.infinity,
          height: double.infinity,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  const Text("Review"),
                  Switch(
                    value: isReview,
                    onChanged: (newValue) {
                      setState(() => isReview = newValue);
                    },
                  ),
                ],
              ),
              const SizedBox(height: 10),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  const Text("Multi Mode"),
                  Switch(
                    value: isMulti,
                    onChanged: (newValue) {
                      setState(() => isMulti = newValue);
                    },
                  ),
                ],
              ),
              MaterialButton(
                color: themeData.primaryColor,
                child: const Text(
                  'All',
                  style: TextStyle(color: Colors.white),
                ),
                onPressed: () {
                  picker(RequestType.all);
                },
              ),
              MaterialButton(
                color: themeData.primaryColor,
                child: const Text(
                  'Images and videos',
                  style: TextStyle(color: Colors.white),
                ),
                onPressed: () {
                  picker(RequestType.common);
                },
              ),
              MaterialButton(
                color: themeData.primaryColor,
                child: const Text(
                  'Image picker',
                  style: TextStyle(color: Colors.white),
                ),
                onPressed: () {
                  picker(RequestType.image);
                },
              ),
              MaterialButton(
                color: themeData.primaryColor,
                child: const Text(
                  'Video picker',
                  style: TextStyle(color: Colors.white),
                ),
                onPressed: () {
                  picker(RequestType.video);
                },
              ),
              MaterialButton(
                color: themeData.primaryColor,
                child: const Text(
                  'Audio picker',
                  style: TextStyle(color: Colors.white),
                ),
                onPressed: () {
                  picker(RequestType.audio);
                },
              ),
            ],
          ),
        ),
      ),
    );
  }

  void picker(RequestType type) {
    MediaPicker.picker(
      context,
      isMulti: isMulti,
      type: type,
      isReview: isReview,
      mulCallback: (List<AssetEntity> assets) {
        //return list if isMulti true
      },
      singleCallback: (AssetEntity asset) {
        //return single item if  isMulti false
      },
    );
  }
}

Libraries

after_layout
loadmore_mixin
media_picker