Multi Image Picker In Flutter || Amazevalley

In this tutorial you will learn how to pick multiple images in flutter using  plugin multi_image_picker 3.0.14 Using this plugin you can 
  • Pick multiple images
    • Instantly pick thousands of images at once, without any delay or blocking the UI thread.
  • Native performance
    • The plugin takes advantage of the two best image picking libraries for Android and iOS, bringing you the best native platform experience.
  • Photos sorted by albums
  • Take a picture option in the grid view
  • Restrict the maximum count of images the user can pick
  • Customizable UI and localizations
  • Thumbnail support
  • Specify the image quality of the original image or thumbnails
  • Read image meta data

DEMO :

Have Look on the main.dart
----

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:multi_image_picker/multi_image_picker.dart';import 'view.dart';
void main() => runApp(new MyApp());
class MyApp extends StatefulWidget {
  @override  _MyAppState createState() => new _MyAppState();}

class _MyAppState extends State<MyApp> {
  List<Asset> images = List<Asset>();  String _error = 'No Error Dectected';
  @override  void initState() {
    super.initState();  }

  Widget buildGridView() {
    return GridView.count(
      crossAxisCount: 3,      children: List.generate(images.length, (index) {
        Asset asset = images[index];        return ViewImages(
          index,          asset,          key: UniqueKey(),        );      }),    );  }

  Future<void> loadAssets() async {
    setState(() {
      images = List<Asset>();    });
    List<Asset> resultList = List<Asset>();    String error = 'No Error Dectected';
    try {
      resultList = await MultiImagePicker.pickImages(
        maxImages: 300,        enableCamera: false,        options: CupertinoOptions(takePhotoIcon: "chat"),      );    } on PlatformException catch (e) {
      error = e.message;    }
    if (!mounted) return;
    setState(() {
      images = resultList;      _error = error;    });  }

  @override  Widget build(BuildContext context) {
    return new MaterialApp(
      debugShowCheckedModeBanner: false,      home: new Scaffold(
        appBar: new AppBar(
          title: const Text('Multiple Images Example'),        ),        body: Column(
          children: <Widget>[
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,              children: <Widget>[
                Text('Select the multiple images '),                RaisedButton(
                  child: Text("Click",style: TextStyle(
                      color: Colors.white                  ),),                  color: Colors.blue,                  onPressed: loadAssets,                ),//                Icon(Icons.camera_alt,color: Colors.blue,)              ],            ),
            Center(
              child:Container(
              padding: EdgeInsets.all(10.0),                child: Text('Error: $_error',style: TextStyle(
                    fontWeight: FontWeight.w900,                    fontStyle: FontStyle.italic                ),),                decoration: BoxDecoration(
                borderRadius: BorderRadius.all(Radius.circular(5.0)),                    border: Border.all(color: Color(0x0FF000000))

                ),              ),            ),            Expanded(
              child: buildGridView(),            )
          ],        ),      ),    );  }
}


view.dart


import 'package:flutter/material.dart';import 'package:multi_image_picker/asset.dart';
class ViewImages extends StatefulWidget {
  final int _index;  final Asset _asset;
  ViewImages(
      this._index,      this._asset, {
        Key key,      }) : super(key: key);
  @override  State<StatefulWidget> createState() => AssetState(this._index, this._asset);}

class AssetState extends State<ViewImages> {
  int _index = 0;  Asset _asset;  AssetState(this._index, this._asset);
  @override  void initState() {
    super.initState();    _loadImage();  }

  void _loadImage() async {
    await this._asset.requestThumbnail(300, 300, quality: 50);
    if (this.mounted) {
      setState(() {});    }
  }

  @override  Widget build(BuildContext context) {
    if (null != this._asset.thumbData) {
      return Image.memory(
        this._asset.thumbData.buffer.asUint8List(),        fit: BoxFit.cover,        gaplessPlayback: true,      );    }

    return Text(
      '${this._index}',      style: Theme.of(context).textTheme.headline,    );  }
}
---


I hope this tutorial help you a lot if you have any query do comment below, Flutter Developers

Comments

  1. Great code love it.

    I have one small issue. When I add a cam picture it is displayed the first time with a wrong orientation when making a portrait picture. If i load the same picture from the gallery it works finaly. How can i fix that issue? ;)

    Best regards

    Gregor

    ReplyDelete
    Replies
    1. Please Update your package and see your camera setting with mirror effect.

      Delete
  2. nice code
    i have an issue
    if max images=5 and if i select 6th one app is crashing.Please help to fix it

    ReplyDelete
  3. C:\Users\Hacker\Documents\login_signup\android\app\src\debug\AndroidManifest.xml Error:
    uses-sdk:minSdkVersion 16 cannot be smaller than version 19 declared in library [:multi_image_picker] C:\Users\Hacker\Documents\login_signup\build\multi_image_picker\intermediate
    s\library_manifest\debug\AndroidManifest.xml as the library might be using APIs not available in 16
    Suggestion: use a compatible library with a minSdk of at most 16,
    or increase this project's minSdk version to at least 19,
    or use tools:overrideLibrary="com.vitanov.multiimagepicker" to force usage (may lead to runtime failures)
    Running Gradle task 'assembleDebug'...
    Running Gradle task 'assembleDebug'... Done 41.1s
    Gradle task assembleDebug failed with exit code 1

    what should i do

    ReplyDelete
  4. thumbData keeps showing red line in view.dart file, why?

    ReplyDelete
    Replies
    1. you should use this version plugin multi_image_picker: 3.0.14 newest version you have to do changes

      Delete
    2. but i'm having multi_image_picker: ^4.6.5+rc.1 and still showing the same

      Delete
  5. Getting this error thumbData is not recognizing and showing error.


    lib/views/View_images.dart:34:29: Error: The getter 'thumbData' isn't defined for the class 'Asset'.
    - 'Asset' is from 'package:multi_image_picker/src/asset.dart' ('/C:/Users/varshith/AppData/Local/Pub/Cache/hosted/pub.dartlang.org/multi_image_picker-4.7.13/lib/src/asset.dart').
    Try correcting the name to the name of an existing getter, or defining a getter or field named 'thumbData'.
    if (null != this._asset.thumbData)
    ^^^^^^^^^
    lib/views/View_images.dart:37:21: Error: The getter 'thumbData' isn't defined for the class 'Asset'.
    - 'Asset' is from 'package:multi_image_picker/src/asset.dart' ('/C:/Users/varshith/AppData/Local/Pub/Cache/hosted/pub.dartlang.org/multi_image_picker-4.7.13/lib/src/asset.dart').
    Try correcting the name to the name of an existing getter, or defining a getter or field named 'thumbData'.
    this._asset.thumbData.buffer.asUint8List(),
    ^^^^^^^^^
    Restarted application in 427ms.

    ReplyDelete
  6. Thank you for your post.

    Multi image picker package was discontinued.

    I recommend freemar_image_picker, support capture & select images in the same view.

    https://pub.dev/packages/freemar_image_picker

    ReplyDelete

Post a Comment

Popular posts from this blog

Listview sort by name in Flutter || Amazevalley

Image Picker In Flutter || Amazevalley