Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
dd87538
scaling and image quality done
balvinderz Sep 25, 2021
c3c1344
image scaling and quality done
balvinderz Sep 25, 2021
cf0ee4d
implement max width max height and imageQuality for web
balvinderz Sep 27, 2021
130f78a
added maxWidth max height and imageQuality for web
balvinderz Sep 27, 2021
b8d3d65
dartfmt
balvinderz Sep 27, 2021
be720c2
revert pubspec.yaml of image_picker
balvinderz Sep 27, 2021
754cec5
run format
balvinderz Sep 27, 2021
942ac46
added image resizer class
balvinderz Sep 30, 2021
982d40a
Merge branch 'master' of https://github.com/flutter/plugins into comp…
balvinderz Sep 30, 2021
6145cf5
Merge branch 'compress_file_web' of https://github.com/balvinderz/plu…
balvinderz Sep 30, 2021
91f92e6
fix calculate size logic
balvinderz Sep 30, 2021
b10408f
fix if condition in resizeImage
balvinderz Sep 30, 2021
42d8191
image resizer done
balvinderz Sep 30, 2021
019a738
added utils test'
balvinderz Sep 30, 2021
2b1842d
update readme
balvinderz Sep 30, 2021
5f7a0dd
add image resizer tests
balvinderz Sep 30, 2021
f61b965
dartfmt
balvinderz Sep 30, 2021
5b477e6
add licenses
balvinderz Sep 30, 2021
60e0b9f
remove path dependancy
balvinderz Sep 30, 2021
7a63323
fix typo and remove extra space
balvinderz Sep 30, 2021
c75b036
fix doc comment
balvinderz Sep 30, 2021
f5e6d45
remove double spaces
balvinderz Sep 30, 2021
d38de67
review changes
balvinderz Oct 2, 2021
5c352f6
fix typo
balvinderz Oct 4, 2021
08b8240
use completeError
balvinderz Oct 4, 2021
7151d71
remove unused imports
balvinderz Oct 4, 2021
a3bbc58
dartfmt
balvinderz Oct 4, 2021
d81990b
fix typo
balvinderz Oct 4, 2021
c90eff3
remove 1 doc comment
balvinderz Oct 4, 2021
811b3fb
update tests and resizing algorithm
balvinderz Oct 5, 2021
3e4d7c1
Review changes
balvinderz Oct 5, 2021
554e996
move image resizer files in src
balvinderz Oct 6, 2021
d15b8b1
dartfmt
balvinderz Oct 6, 2021
b87f0cf
dartfmt again
balvinderz Oct 6, 2021
d99a702
Fix some review comments
ditman Oct 16, 2021
5e825ab
Slight update in the CHANGELOG
ditman Oct 16, 2021
c4d057e
Merge branch 'master' into compress_file_web
ditman Oct 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
dartfmt
  • Loading branch information
balvinderz committed Sep 27, 2021
commit b8d3d65ccb376a166256e6ab71b4b326cc177c6b
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'dart:async';
import 'dart:html' as html;

import 'package:flutter_web_plugins/flutter_web_plugins.dart';
import 'package:image/image.dart';
import 'package:meta/meta.dart';
import 'package:image_picker_platform_interface/image_picker_platform_interface.dart';

Expand Down Expand Up @@ -93,7 +92,7 @@ class ImagePickerPlugin extends ImagePickerPlatform {
String? capture,
}) {
html.FileUploadInputElement input =
createInputElement(accept, capture) as html.FileUploadInputElement;
createInputElement(accept, capture) as html.FileUploadInputElement;
_injectAndActivate(input);
return _getSelectedFile(input);
}
Expand Down Expand Up @@ -180,13 +179,12 @@ class ImagePickerPlugin extends ImagePickerPlatform {
///
/// See https://caniuse.com/#feat=html-media-capture
@visibleForTesting
Future<List<XFile>> getFiles(
{String? accept,
String? capture,
bool multiple = false,
double? maxWidth,
double? maxHeight,
int? imageQuality}) {
Future<List<XFile>> getFiles({String? accept,
String? capture,
bool multiple = false,
double? maxWidth,
double? maxHeight,
int? imageQuality}) {
html.FileUploadInputElement input = createInputElement(
accept,
capture,
Expand Down Expand Up @@ -222,7 +220,7 @@ class ImagePickerPlugin extends ImagePickerPlatform {
/// Returns a list of selected files.
List<html.File>? _handleOnChangeEvent(html.Event event) {
final html.FileUploadInputElement input =
event.target as html.FileUploadInputElement;
event.target as html.FileUploadInputElement;
return _getFilesFromInput(input);
}

Expand Down Expand Up @@ -260,7 +258,7 @@ class ImagePickerPlugin extends ImagePickerPlatform {
//Convert the file if one of the parameter is not null
if (imageQuality != null || maxWidth != null || maxHeight != null) {
final convertedFileUris = await Future.wait(files.map((e) async =>
await _getCompressedUri(e, imageQuality, maxHeight, maxWidth)));
await _getCompressedUri(e, imageQuality, maxHeight, maxWidth)));

int index = 0;
_completer.complete(files.map((file) {
Expand Down Expand Up @@ -291,7 +289,8 @@ class ImagePickerPlugin extends ImagePickerPlatform {
var target = html.querySelector('#${id}');
if (target == null) {
final html.Element targetElement =
html.Element.tag('flt-image-picker-inputs')..id = id;
html.Element.tag('flt-image-picker-inputs')
..id = id;

html.querySelector('body')!.children.add(targetElement);
target = targetElement;
Expand All @@ -302,11 +301,10 @@ class ImagePickerPlugin extends ImagePickerPlatform {
/// Creates an input element that accepts certain file types, and
/// allows to `capture` from the device's cameras (where supported)
@visibleForTesting
html.Element createInputElement(
String? accept,
String? capture, {
bool multiple = false,
}) {
html.Element createInputElement(String? accept,
String? capture, {
bool multiple = false,
}) {
if (_hasOverrides) {
return _overrides!.createInputElement(accept, capture);
}
Expand Down Expand Up @@ -352,7 +350,8 @@ class ImagePickerPlugin extends ImagePickerPlatform {
ctx.drawImageScaled(image, 0, 0, canvas.width!, canvas.height!);
}
final blob =
await canvas.toBlob(file.type, (imageQuality ?? 100) / 100.0); // Image quality only works for jpeg images
await canvas.toBlob(file.type, (imageQuality ?? 100) /
100.0); // Image quality only works for jpeg images
_completer.complete(html.Url.createObjectUrlFromBlob(blob));
});
image.onError.listen((event) {
Expand All @@ -362,8 +361,8 @@ class ImagePickerPlugin extends ImagePickerPlatform {
return _completer.future;
}

List<int> _calculateSize(
html.ImageElement img, double maxWidth, double maxHeight) {
List<int> _calculateSize(html.ImageElement img, double maxWidth,
double maxHeight) {
var width = img.width!;
var height = img.height!;

Expand All @@ -384,12 +383,15 @@ class ImagePickerPlugin extends ImagePickerPlatform {
}

extension on html.File {
XFile toXFile({String? path}) => XFile(
XFile toXFile({String? path}) =>
XFile(
path ?? html.Url.createObjectUrl(this),
name: this.name,
length: this.size,
lastModified: DateTime.fromMillisecondsSinceEpoch(
this.lastModified ?? DateTime.now().millisecondsSinceEpoch,
this.lastModified ?? DateTime
.now()
.millisecondsSinceEpoch,
),
mimeType: this.type,
);
Expand All @@ -399,14 +401,14 @@ extension on html.File {
/// A function that creates a file input with the passed in `accept` and `capture` attributes.
@visibleForTesting
typedef OverrideCreateInputFunction = html.Element Function(
String? accept,
String? capture,
);
String? accept,
String? capture,
);

/// A function that extracts list of files from the file `input` passed in.
@visibleForTesting
typedef OverrideExtractMultipleFilesFromInputFunction = List<html.File>
Function(html.Element? input);
Function(html.Element? input);

/// Overrides for some of the functionality above.
@visibleForTesting
Expand Down