Skip to content

Commit

Permalink
Merge pull request #24 from Ahmadre/prepare_v2.0.2
Browse files Browse the repository at this point in the history
Prepare v2.0.2
  • Loading branch information
TesteurManiak authored Apr 26, 2021
2 parents a02404b + edc61ba commit fc6d667
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 71 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ jobs:
- uses: subosito/flutter-action@v1
- run: flutter pub get
- run: flutter format --set-exit-if-changed .
- run: flutter analyze .
- name: Analyze project source
run: flutter analyze
working-directory: ./lib
- name: Build example
run: flutter build web
working-directory: example
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.2 - [27/04/2021]

* Fixed issue [#22](https://github.com/Ahmadre/image_picker_web/issues/22)

## 2.0.1 - [30/03/2021]

* Fixed `FutureOr<Map<String, dynamic>>` cast
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# ImagePickerWeb

[![Issues](https://img.shields.io/github/issues/Ahmadre/image_picker_web)](https://github.com/Ahmadre/image_picker_web/issues)
[![Forks](https://img.shields.io/github/forks/Ahmadre/image_picker_web)](https://github.com/Ahmadre/image_picker_web/network/members)
[![Stars](https://img.shields.io/github/stars/Ahmadre/image_picker_web)](https://github.com/Ahmadre/image_picker_web/stargazers)
[![Pub Version](https://img.shields.io/pub/v/image_picker_web?color=blue&logo=dart)](https://pub.dev/packages/image_picker_web)
[![Flutter Web CI](https://github.com/Ahmadre/image_picker_web/actions/workflows/dart.yml/badge.svg)](https://github.com/Ahmadre/image_picker_web/actions/workflows/dart.yml)

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](https://github.com/AlvaroVasconcelos) for the implementation of picking images in his plugin: [flutter_web_image_picker](https://github.com/AlvaroVasconcelos/flutter_web_image_picker)

Expand Down
80 changes: 29 additions & 51 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,83 +1,61 @@
analyzer:
exclude:
# Ignore generated files
- '**/*.g.dart'
- 'lib/src/generated/*.dart'
- 'lib/src/image_provider/_load_async_web.dart'

errors:
unused_import: warning
unused_local_variable: warning
dead_code: warning
invalid_override_of_non_virtual_member: error
# Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
#
# Google internally enforced rules. See README.md for more information,
# including a list of lints that are intentionally _not_ enforced.

linter:
rules:
- always_declare_return_types
- always_require_non_null_named_parameters
- annotate_overrides
- avoid_empty_else
- avoid_function_literals_in_foreach_calls
- avoid_init_to_null
- avoid_void_async
- await_only_futures
- avoid_null_checks_in_equality_operators
- avoid_renaming_method_parameters
- avoid_relative_lib_imports
- avoid_return_types_on_setters
- avoid_returning_null
- avoid_returning_null_for_void
- avoid_shadowing_type_parameters
- avoid_single_cascade_in_expression_statements
- avoid_types_as_parameter_names
- avoid_relative_lib_imports
- avoid_unused_constructor_parameters
- camel_case_types
- cancel_subscriptions
- control_flow_in_finally
- directives_ordering
- await_only_futures
- camel_case_extensions
- curly_braces_in_flow_control_structures
- empty_catches
- empty_constructor_bodies
- empty_statements
- hash_and_equals
- invariant_booleans
- iterable_contains_unrelated_type
- library_names
- library_prefixes
- list_remove_unrelated_type
- no_adjacent_strings_in_list
- no_duplicate_case_values
- non_constant_identifier_names
- overridden_fields
- package_api_docs
- package_names
- package_prefixed_library_names
- null_closures
- omit_local_variable_types
- prefer_adjacent_string_concatenation
- prefer_collection_literals
- prefer_conditional_assignment
- prefer_const_constructors
- prefer_contains
- prefer_equal_for_default_values
- prefer_final_fields
- prefer_initializing_formals
- prefer_for_elements_to_map_fromIterable
- prefer_generic_function_type_aliases
- prefer_if_null_operators
- prefer_inlined_adds
- prefer_is_empty
- prefer_is_not_empty
- prefer_iterable_whereType
- prefer_single_quotes
- prefer_typing_uninitialized_variables
- prefer_spread_collections
- recursive_getters
- slash_for_doc_comments
- sort_pub_dependencies
- test_types_in_equals
- throw_in_finally
- sort_child_properties_last
- type_init_formals
- unawaited_futures
- unnecessary_await_in_return
- unnecessary_brace_in_string_interps
- unnecessary_const
- unnecessary_getters_setters
- unnecessary_lambdas
- unnecessary_null_aware_assignments
- unnecessary_statements
- unnecessary_new
- unnecessary_null_in_if_null_operators
- unnecessary_this
- unrelated_type_equality_checks
- unsafe_html
- use_full_hex_values_for_flutter_colors
- use_function_type_syntax_for_parameters
- use_rethrow_when_possible
- valid_regexps
# Additional Dart 2.3 lints
- prefer_spread_collections
- prefer_if_elements_to_conditional_expressions
- prefer_for_elements_to_map_fromIterable
- valid_regexps
19 changes: 11 additions & 8 deletions lib/image_picker_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ class ImagePickerWeb {
});
}

static const MethodChannel _methodChannel =
const MethodChannel('image_picker_web');
static const MethodChannel _methodChannel = MethodChannel('image_picker_web');

static Future<html.File?> _pickFile(String type) async {
final completer = Completer<List<html.File>>();
final html.FileUploadInputElement input = html.FileUploadInputElement();
final input = html.FileUploadInputElement();
input.accept = '$type/*';
input.click();
input.addEventListener('change', (e) async {
Expand All @@ -61,7 +60,7 @@ class ImagePickerWeb {
/// source: https://stackoverflow.com/a/59420655/9942346
Future<List<html.File>?> _pickMultiFiles(String type) async {
final completer = Completer<List<html.File>>();
final html.FileUploadInputElement input = html.FileUploadInputElement();
final input = html.FileUploadInputElement();
input.multiple = true;
input.accept = '$type/*';
input.click();
Expand Down Expand Up @@ -149,12 +148,16 @@ class ImagePickerWeb {
case ImageType.file:
return images;
case ImageType.bytes:
List<Uint8List> files = [];
for (final img in images) files.add(await img.asBytes());
var files = <Uint8List>[];
for (final img in images) {
files.add(await img.asBytes());
}
return files.isEmpty ? null : files;
case ImageType.widget:
List<Uint8List> files = [];
for (final img in images) files.add(await img.asBytes());
var files = <Uint8List>[];
for (final img in images) {
files.add(await img.asBytes());
}
if (files.isEmpty) return null;
return files.map<Image>((e) => Image.memory(e)).toList();
default:
Expand Down
4 changes: 2 additions & 2 deletions lib/src/extensions/file_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import 'dart:typed_data';

extension FileModifier on html.File {
Future<Uint8List> asBytes() async {
final Completer<List<int>> bytesFile = Completer<List<int>>();
final html.FileReader reader = html.FileReader();
final bytesFile = Completer<List<int>>();
final reader = html.FileReader();
reader.onLoad.listen(
(event) => bytesFile.complete(reader.result as FutureOr<List<int>>?));
reader.readAsArrayBuffer(this);
Expand Down
12 changes: 6 additions & 6 deletions lib/src/web_image_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import 'dart:html' as html;

class WebImagePicker {
Future<Map<String, dynamic>?> pickImage() async {
final Map<String, dynamic> data = {};
final html.FileUploadInputElement input = html.FileUploadInputElement();
input..accept = 'image/*';
final data = <String, dynamic>{};
final input = html.FileUploadInputElement();
input.accept = 'image/*';
input.click();
html.document.body!.append(input);
await input.onChange.first;
Expand All @@ -23,9 +23,9 @@ class WebImagePicker {
}

Future<Map<String, dynamic>?> pickVideo() async {
final Map<String, dynamic> data = {};
final html.FileUploadInputElement input = html.FileUploadInputElement();
input..accept = 'video/*';
final data = <String, dynamic>{};
final input = html.FileUploadInputElement();
input.accept = 'video/*';
input.click();
html.document.body!.append(input);
await input.onChange.first;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: image_picker_web
description: Flutter Web Plugin to pick Images (as Widget, File or Uint8List)
and Videos (as File or Uint8List)
version: 2.0.1
version: 2.0.2
repository: https://github.com/Ahmadre/image_picker_web

environment:
Expand Down
2 changes: 1 addition & 1 deletion test/image_picker_web_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
const MethodChannel channel = MethodChannel('image_picker_web');
const channel = MethodChannel('image_picker_web');

TestWidgetsFlutterBinding.ensureInitialized();

Expand Down

0 comments on commit fc6d667

Please sign in to comment.