Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

imagepickerweb

this web-plugin allows flutter web to pick images (as file, widget or uint8list) and videos (as file or uint8list). many thanks goes to alvarovasconcelos for the implementation of picking images in his plugin: flutter_web_image_picker

examplegif

disclaimer for videos

  • till now [mar. 2020] it’s not possible (due to security reasons) to play a local video file (see also video_player_web). but you can retreive the file and upload them somewhere and play it as a network source.

getting started

add image_picker_web to your pubspec.yaml:

    image_picker_web: any

picking images

load image as image widget:

    image frompicker = await imagepickerweb.getimage(outputtype: imagetype.widget);

    if (frompicker != null) {
      setstate(() {
        pickedimage = frompicker;
      });
    }

setting outputtype to imagetype.bytes:

    uint8list bytesfrompicker =
        await imagepickerweb.getimage(outputtype: imagetype.bytes);

    if (bytesfrompicker != null) {
      debugprint(bytesfrompicker.tostring());
    }

setting outputtype to imagetype.file:

    html.file imagefile =
        await imagepickerweb.getimage(outputtype: imagetype.file);

    if (imagefile != null) {
      debugprint(imagefile.name.tostring());
    }

how do i get all informations out of my image/video (e.g. image and file in one run)?

besides the standard getimage() or getvideo() methods you can use the getters:

  • getimageinfo or
  • getvideoinfo to acheive this.

full example

import 'dart:html' as html;
 
import 'package:mime_type/mime_type.dart';
import 'package:path/path.dart' as path;
import 'package:image_picker_web/image_picker_web.dart';
import 'package:flutter/material.dart';

 html.file _cloudfile;
 var _filebytes;
 image _imagewidget;
 
 future<void> getmultipleimageinfos() async {
    var mediadata = await imagepickerweb.getimageinfo;
    string mimetype = mime(path.basename(mediadata.filename));
    html.file mediafile =
        new html.file(mediadata.data, mediadata.filename, {'type': mimetype});

    if (mediafile != null) {
      setstate(() {
        _cloudfile = mediafile;
        _filebytes = mediadata.data;
        _imagewidget = image.memory(mediadata.data);
      });
    }
  }

with getmultipleimageinfos() you can get all three available types in one call.

picking videos

to load a video as html.file do:

    html.file videofile = await imagepickerweb.getvideo(outputtype: videotype.file);

    debugprint('---picked video file---');
    debugprint(videofile.name.tostring());

to load a video as uint8list do:

    uint8list videodata = await imagepickerweb.getvideo(outputtype: videotype.bytes);

    debugprint('---picked video bytes---');
    debugprint(videodata.tostring());

reminder: don’t use uint8list retreivement for big video files! flutter can’t handle that. pick bigger sized videos and high-resolution videos as html.file!

after you uploaded your video somewhere hosted, you can retreive the network url to play it.

mediainfos

  • the methods getvideoinfo and getimageinfo are also available and you can use them to retreive further informations about your picked source.

Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Comments are closed.