image_picker_for_web

3.1.1

Web platform implementation of image_picker

Download archive

Readme

image_picker_for_web

A web implementation of image_picker.

Limitations on the web platform

XFile

This plugin uses XFile objects to abstract files picked/created by the user.

Read more about XFile on the web in package:cross_file's README.

input file "accept"

In order to filter only video/image content, some browsers offer an accept attribute in their input type="file" form elements:

Data on support for the input-file-accept feature across the major browsers from caniuse.com

This feature is just a convenience for users, not validation.

Users can override this setting on their browsers. You must validate in your app (or server) that the user has picked the file type that you can handle.

input file "capture"

In order to "take a photo", some mobile browsers offer a capture attribute:

Data on support for the html-media-capture feature across the major browsers from caniuse.com

Each browser may implement capture any way they please, so it may (or may not) make a difference in your users' experience.

input file "cancel"

The cancel event used by the plugin to detect when users close the file selector without picking a file is relatively new, and will only work in recent browsers.

ImagePickerOptions support

The ImagePickerOptions configuration object allows passing resize (maxWidth, maxHeight) and quality (imageQuality) parameters to some methods of this plugin, which in other platforms control how selected images are resized or re-encoded.

On the web:

  • maxWidth, maxHeight and imageQuality are not supported for gif images.
  • imageQuality only affects jpg and webp images.

getVideo()

The argument maxDuration is not supported on the web.

Usage

Import the package

This package is endorsed, which means you can simply use image_picker normally. This package will be automatically included in your app when you do, so you do not need to add it to your pubspec.yaml.

However, if you import this package to use any of its APIs directly, you should add it to your pubspec.yaml as usual.

Use the plugin

You should be able to use package:image_picker almost as normal.

Once the user has picked a file, the returned XFile instance will contain a network-accessible Blob URL (pointing to a location within the browser).

The instance will also let you retrieve the bytes of the selected file across all platforms.

If you want to use the path directly, your code would need look like this:

if (kIsWeb) {
  image = Image.network(pickedFile.path);
} else {
  image = Image.file(File(pickedFile.path));
}

Or, using bytes:

image = Image.memory(await pickedFile.readAsBytes());
Changelog

3.1.1

  • Uses CanvasRenderingContext2D.drawImage instead of the deprecated drawImageScaled.
  • Updates minimum supported SDK version to Flutter 3.32/Dart 3.8.

3.1.0

  • Adds support for getMultiVideoWithOptions.
  • Updates minimum supported SDK version to Flutter 3.27/Dart 3.6.

3.0.6

  • Updates minimum supported SDK version to Flutter 3.22/Dart 3.4.
  • Extends the mime package version constraint from ^1.0.4 to >=1.0.4 <3.0.0.

3.0.5

  • Adds support for web: ^1.0.0.

3.0.4

  • Improves README example and updates it to use code excerpts.

3.0.3

  • Migrates package and tests to package:web.
  • Updates minimum supported SDK version to Flutter 3.19/Dart 3.3.

3.0.2

  • Updates minimum supported SDK version to Flutter 3.10/Dart 3.0.
  • Removes input element after completion

3.0.1

  • Adds pub topics to package metadata.
  • Updates minimum supported SDK version to Flutter 3.7/Dart 2.19.

3.0.0

  • BREAKING CHANGE: Removes all code and tests mentioning PickedFile.
  • Listens to cancel event on file selection. When the selection is canceled:
    • Future<XFile?> methods return null
    • Future<List<XFile>> methods return an empty list.

2.2.0

  • Adds getMedia method.
  • Updates minimum supported SDK version to Flutter 3.3/Dart 2.18.

2.1.12

  • Clarifies explanation of endorsement in README.
  • Aligns Dart and Flutter SDK constraints.

2.1.11

  • Updates links for the merge of flutter/plugins into flutter/packages.
  • Updates minimum Flutter version to 3.0.

2.1.10

  • Updates code for no_leading_underscores_for_local_identifiers lint.

2.1.9

  • Updates imports for prefer_relative_imports.
  • Updates minimum Flutter version to 2.10.
  • Fixes violations of new analysis option use_named_constants.

2.1.8

  • Minor fixes for new analysis options.

2.1.7

  • Fixes library_private_types_in_public_api, sort_child_properties_last and use_key_in_widget_constructors lint warnings.

2.1.6

  • Internal code cleanup for stricter analysis options.

2.1.5

  • Removes dependency on meta.

2.1.4

  • Implemented maxWidth, maxHeight and imageQuality when selecting images (except for gifs).

2.1.3

  • Add implements to pubspec.

2.1.2

  • Updated installation instructions in README.

2.1.1

  • Implemented getMultiImage.
  • Initialized the following XFile attributes for picked files:
    • name, length, mimeType and lastModified.

2.1.0

  • Implemented getImage, getVideo and getFile methods that return XFile instances.
  • Move tests to example directory, so they run as integration_tests with flutter drive.

2.0.0

  • Migrate to null safety.
  • Add doc comments to point out that some arguments aren't supported on the web.

0.1.0+3

  • Update Flutter SDK constraint.

0.1.0+2

  • Adds Video MIME Types for the safari browser for acception

0.1.0+1

  • Remove android directory.

0.1.0

  • Initial open-source release.

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add image_picker_for_web
pubspec.yaml
name: image_picker_for_web
description: Web platform implementation of image_picker
repository: https://github.com/flutter/packages/tree/main/packages/image_picker/image_picker_for_web
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22
version: 3.1.1

environment:
  sdk: ^3.8.0
  flutter: ">=3.32.0"

flutter:
  plugin:
    implements: image_picker
    platforms:
      web:
        pluginClass: ImagePickerPlugin
        fileName: image_picker_for_web.dart

dependencies:
  flutter:
    sdk: flutter
  flutter_web_plugins:
    sdk: flutter
  image_picker_platform_interface: ^2.11.0
  mime: ">=1.0.4 <3.0.0"
  web: ">=0.5.1 <2.0.0"

dev_dependencies:
  flutter_test:
    sdk: flutter

topics:
  - camera
  - image-picker
  - files
  - file-selection

Version history

VersionPublishedArchiveSHA-256
0.1.0On demandDownload7c1ab316…080f16
0.1.0+1On demandDownload1fe458c3…d7a307
0.1.0+2On demandDownload7bac0654…3ab5ca
2.0.0-nullsafetyOn demandDownload95b07428…be5fb8
2.0.0On demandDownload3a19a450…f7bdbc
2.1.0On demandDownload1a21500e…97f53e
2.1.1On demandDownloaddad86416…b59fc4
2.1.2On demandDownload8c3ea4a4…5fe4cd
2.1.3On demandDownload111b1405…139e10
2.1.4On demandDownload32414704…4f4ce2
2.1.5On demandDownload1f21a49e…bfb9f5
2.1.6On demandDownload837609cc…9a9333
2.1.7On demandDownload8c1fb06d…3fe26f
2.1.8On demandDownload60f306ff…0f0e0e
2.1.9On demandDownload0249a6f4…35bac8
2.1.10On demandDownload7d319fb7…863899
2.1.11On demandDownload66fc6e38…b85b34
2.1.12On demandDownload98f50d6b…2c081c
2.2.0On demandDownload869fe8a6…c797f0
3.0.0On demandDownload8b6c160c…da8765
3.0.1On demandDownload50bc9ae6…347ef7
3.0.2On demandDownloade2423c53…a730a3
3.0.3On demandDownload6a1704fd…eac954
3.0.4On demandDownload5d6eb130…b5b5f3
3.0.5On demandDownload65d94623…b39e50
3.0.6On demandDownload717eb042…b7bb83
3.1.0On demandDownload40c2a6a0…7269b6
3.1.1Cached · Upstream SHA-256 matchedDownload66257a31…850214

Dependencies

flutter { "sdk": "flutter" }

flutter_web_plugins { "sdk": "flutter" }

image_picker_platform_interface "^2.11.0"

mime "\u003e=1.0.4 \u003c3.0.0"

web "\u003e=0.5.1 \u003c2.0.0"