From 2aa11f522236b9f3fda7854484b766d27d75ffa1 Mon Sep 17 00:00:00 2001 From: Guillaume Roux Date: Tue, 27 Apr 2021 00:33:35 +0200 Subject: [PATCH 1/3] update analysis_options.yaml --- CHANGELOG.md | 4 ++ analysis_options.yaml | 80 +++++++++---------------- lib/image_picker_web.dart | 19 +++--- lib/src/extensions/file_extensions.dart | 4 +- lib/src/web_image_picker.dart | 12 ++-- pubspec.yaml | 2 +- test/image_picker_web_test.dart | 2 +- 7 files changed, 54 insertions(+), 69 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b13b9c..b44030c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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>` cast diff --git a/analysis_options.yaml b/analysis_options.yaml index a86ffe6..2c1167e 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -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 \ No newline at end of file + - valid_regexps \ No newline at end of file diff --git a/lib/image_picker_web.dart b/lib/image_picker_web.dart index b12144d..57ba5f3 100644 --- a/lib/image_picker_web.dart +++ b/lib/image_picker_web.dart @@ -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 _pickFile(String type) async { final completer = Completer>(); - final html.FileUploadInputElement input = html.FileUploadInputElement(); + final input = html.FileUploadInputElement(); input.accept = '$type/*'; input.click(); input.addEventListener('change', (e) async { @@ -61,7 +60,7 @@ class ImagePickerWeb { /// source: https://stackoverflow.com/a/59420655/9942346 Future?> _pickMultiFiles(String type) async { final completer = Completer>(); - final html.FileUploadInputElement input = html.FileUploadInputElement(); + final input = html.FileUploadInputElement(); input.multiple = true; input.accept = '$type/*'; input.click(); @@ -149,12 +148,16 @@ class ImagePickerWeb { case ImageType.file: return images; case ImageType.bytes: - List files = []; - for (final img in images) files.add(await img.asBytes()); + var files = []; + for (final img in images) { + files.add(await img.asBytes()); + } return files.isEmpty ? null : files; case ImageType.widget: - List files = []; - for (final img in images) files.add(await img.asBytes()); + var files = []; + for (final img in images) { + files.add(await img.asBytes()); + } if (files.isEmpty) return null; return files.map((e) => Image.memory(e)).toList(); default: diff --git a/lib/src/extensions/file_extensions.dart b/lib/src/extensions/file_extensions.dart index 8d1e0bb..b241374 100644 --- a/lib/src/extensions/file_extensions.dart +++ b/lib/src/extensions/file_extensions.dart @@ -5,8 +5,8 @@ import 'dart:typed_data'; extension FileModifier on html.File { Future asBytes() async { - final Completer> bytesFile = Completer>(); - final html.FileReader reader = html.FileReader(); + final bytesFile = Completer>(); + final reader = html.FileReader(); reader.onLoad.listen( (event) => bytesFile.complete(reader.result as FutureOr>?)); reader.readAsArrayBuffer(this); diff --git a/lib/src/web_image_picker.dart b/lib/src/web_image_picker.dart index bf810ad..253474c 100644 --- a/lib/src/web_image_picker.dart +++ b/lib/src/web_image_picker.dart @@ -3,9 +3,9 @@ import 'dart:html' as html; class WebImagePicker { Future?> pickImage() async { - final Map data = {}; - final html.FileUploadInputElement input = html.FileUploadInputElement(); - input..accept = 'image/*'; + final data = {}; + final input = html.FileUploadInputElement(); + input.accept = 'image/*'; input.click(); html.document.body!.append(input); await input.onChange.first; @@ -23,9 +23,9 @@ class WebImagePicker { } Future?> pickVideo() async { - final Map data = {}; - final html.FileUploadInputElement input = html.FileUploadInputElement(); - input..accept = 'video/*'; + final data = {}; + final input = html.FileUploadInputElement(); + input.accept = 'video/*'; input.click(); html.document.body!.append(input); await input.onChange.first; diff --git a/pubspec.yaml b/pubspec.yaml index 219332f..bb6ec9c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: diff --git a/test/image_picker_web_test.dart b/test/image_picker_web_test.dart index e690b1a..9eef64e 100644 --- a/test/image_picker_web_test.dart +++ b/test/image_picker_web_test.dart @@ -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(); From 38731001ad452e17e11c59f3bd5e7139cc6c01af Mon Sep 17 00:00:00 2001 From: Guillaume Roux Date: Tue, 27 Apr 2021 00:35:59 +0200 Subject: [PATCH 2/3] update REAMDE --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 83a0802..dd9bba1 100644 --- a/README.md +++ b/README.md @@ -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) From edc61ba0b5873804ee2008cd4d16d9b83f045533 Mon Sep 17 00:00:00 2001 From: Guillaume Roux Date: Tue, 27 Apr 2021 00:40:08 +0200 Subject: [PATCH 3/3] Update dart.yml --- .github/workflows/dart.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index d7ec13c..9727b63 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -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