flutter ui upload multiple image

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

import 'package:multi_image_picker/multi_image_picker.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 = 'Selectionner une image';

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

  Widget buildGridView() {
    return GridView.count(
      crossAxisCount: 3,
      children: List.generate(images.length, (index) {
        Asset asset = images[index];
        return AssetThumb(
          asset: asset,
          width: 300,
          height: 300,
        );
      }),
    );
  }

  Future<void> loadAssets() async {
    List<Asset> resultList = List<Asset>();
    String error = 'No Error Dectected';

    try {
      resultList = await MultiImagePicker.pickImages(
        maxImages: 4,
        enableCamera: true,
        selectedAssets: images,
        cupertinoOptions: CupertinoOptions(takePhotoIcon: "chat"),
        materialOptions: MaterialOptions(
          actionBarColor: "#abcdef",
          actionBarTitle: "Example App",
          allViewTitle: "All Photos",
          useDetailsView: false,
          selectCircleStrokeColor: "#000000",
        ),
      );
    } on Exception catch (e) {
      error = e.toString();
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      images = resultList;
      _error = error;
    });
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: const Text('Image Upload'),
          centerTitle: true,
        ),
        body: Column(
          children: <Widget>[
            //Center(child: Text('Error: $_error')),
            Text('Ajouter image du produit'),
            RaisedButton(
              child: Text("Selectionner "),
              onPressed: loadAssets,
            ),
            Expanded(
              child: buildGridView(),
            )
          ],
        ),
      ),
    );
  }
}

4.33
6
Mpiftetsia 65 points

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

import 'package:multi_image_picker/multi_image_picker.dart';

void main() =&gt; runApp(new MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() =&gt; new _MyAppState();
}

class _MyAppState extends State&lt;MyApp&gt; {
  List&lt;Asset&gt; images = List&lt;Asset&gt;();
  String _error;

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

  Widget buildGridView() {
    if (images != null)
      return GridView.count(
        crossAxisCount: 3,
        children: List.generate(images.length, (index) {
          Asset asset = images[index];
          return AssetThumb(
            asset: asset,
            width: 300,
            height: 300,
          );
        }),
      );
    else
      return Container(color: Colors.white);
  }

  Future&lt;void&gt; loadAssets() async {
    setState(() {
      images = List&lt;Asset&gt;();
    });

    List&lt;Asset&gt; resultList;
    String error;

    try {
      resultList = await MultiImagePicker.pickImages(
        maxImages: 300,
      );
    } on Exception catch (e) {
      error = e.toString();
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      images = resultList;
      if (error == null) _error = 'No Error Dectected';
    });
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Column(
          children: &lt;Widget&gt;[
            Center(child: Text('Error: $_error')),
            RaisedButton(
              child: Text(&quot;Pick images&quot;),
              onPressed: loadAssets,
            ),
            Expanded(
              child: buildGridView(),
            )
          ],
        ),
      ),
    );
  }
}

4.33 (6 Votes)
0
3
1
Petamelo 110 points

                                    import 'dart:io';

//import 'package:blog_app/models/ImageUploadModel.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';

class SingleImageUpload extends StatefulWidget {
  @override
  _SingleImageUploadState createState() {
    return _SingleImageUploadState();
  }
}

class _SingleImageUploadState extends State&lt;SingleImageUpload&gt; {
  List&lt;Object&gt; images = List&lt;Object&gt;();
  Future&lt;File&gt; _imageFile;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    setState(() {
      images.add(&quot;Add Image&quot;);
      images.add(&quot;Add Image&quot;);
     // images.add(&quot;Add Image&quot;);
     // images.add(&quot;Add Image&quot;);
    });
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          centerTitle: true,
          title: const Text('Upload image'),
        ),
        body: Column(
          children: &lt;Widget&gt;[
            Expanded(
              child: buildGridView(),
            ),
          ],
        ),
      ),
    );
  }

  Widget buildGridView() {
    return GridView.count(
      shrinkWrap: true,
      crossAxisCount: 3,
      childAspectRatio: 1,
      children: List.generate(images.length, (index) {
        if (images[index] is ImageUploadModel) {
          ImageUploadModel uploadModel = images[index];
          return Card(
            clipBehavior: Clip.antiAlias,
            child: Stack(
              children: &lt;Widget&gt;[
                Image.file(
                  uploadModel.imageFile,
                  width: 300,
                  height: 300,
                ),
                Positioned(
                  right: 5,
                  top: 5,
                  child: InkWell(
                    child: Icon(
                      Icons.remove_circle,
                      size: 20,
                      color: Colors.red,
                    ),
                    onTap: () {
                      setState(() {
                        images.replaceRange(index, index + 1, ['Add Image']);
                      });
                    },
                  ),
                ),
              ],
            ),
          );
        } else {
          return Card(
            child: IconButton(
              icon: Icon(Icons.add),
              onPressed: () {
                _onAddImageClick(index);
              },
            ),
          );
        }
      }),
    );
  }

  Future _onAddImageClick(int index) async {
    setState(() {
      _imageFile = ImagePicker.pickImage(source: ImageSource.gallery);
      getFileImage(index);
    });
  }

  void getFileImage(int index) async {
//    var dir = await path_provider.getTemporaryDirectory();

    _imageFile.then((file) async {
      setState(() {
        ImageUploadModel imageUpload = new ImageUploadModel();
        imageUpload.isUploaded = false;
        imageUpload.uploading = false;
        imageUpload.imageFile = file;
        imageUpload.imageUrl = '';
        images.replaceRange(index, index + 1, [imageUpload]);
      });
    });
  }
}

class ImageUploadModel {
  bool isUploaded;
  bool uploading;
  File imageFile;
  String imageUrl;

  ImageUploadModel({
    this.isUploaded,
    this.uploading,
    this.imageFile,
    this.imageUrl,
  });
}

3 (1 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
flutter how to save multiple image in api flutter upload many images flutter upload multi image upload multiple image dio flutter uploading multiple images in flutter to server flutter upload multiple image to server how to upload multi image in flutter with nullety how to upload multiimage flutter how to upload multiimage in flutter multiple image upload in flutter github multiple image upload in flutter flutter multiple image upload widget upload images via multiple field flutter upload image via multiple field flutter upload multiple images flutter and php multi image picker flutter upload to server multi image picker flutter upload to serve flutter multiple image upload upload multiple images to firebase with form flutter Upload multiple images to firebase flutter multiple image upload to firebase storage in flutter multiple image upload flutter Multiple Image Upload Using Multipart In Flutter flutter multiple image files upload using formdata upload multiple images in flutter multiple image upload to Rest APi Flutter How to upload multiple images to api flutter upload muktiple images in flutter widget to upload multiple image what is the field when upload multiple images in mutlipart file flutter multiple image files submit in mutlipart file in flutter upload multiple images flutter multi image upload to firbase flutter packge to upload multi image flutter how to upload multi image flutter how to upload multi image flutte upload multi image to firbebase flutter flutter multipart upload image how to upload multiple image in flutter upload image dio flutter multer image upload multer flutter save multiple image in flutter upload image with multipart flutter how to upload multiple images in flutter select and upload multiple image in flutter flutter upload multimage and compress how to upload multiple images to firebase in flutter flutter upload multiple images to node js multiple image picker flutter upload upload multiple image in flutter with dio Multipart flutter upload multiple image to firebase storage upload multiple images to server from flutter flutter send images for upload with multer flutter upload multiple images Flutter upload image multipart update multiple image flutter flutter dio upload multiple images flutter upload multiple files function to upload multiple image in flutter in firebase storage function to upload multiple image in flutter upload multiple photos flutter upload multiple image in firestore in flutter and getdownloadurl Upload multi image in flutter multi image upload flutter image upload Ui flutter laravel multiple image upload flutter upload multi image flutter flutter uploading multiple image upload multiple file flutter map [] upload multiple files flutter php flutter ui upload multiple image
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source