diff --git a/analysis_options.yaml b/analysis_options.yaml index 2b4cd4f49..dcde1400b 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,34 +1,20 @@ -# This file was copied from flutter/plugins/analysis_options.yaml. +# This file is a copy of analysis_options.yaml from flutter/packages repo +# as of 2022-12-15. analyzer: - strong-mode: - implicit-casts: false - implicit-dynamic: false + language: + strict-casts: true + strict-raw-types: true errors: - # treat missing required parameters as a warning (not a hint) - missing_required_param: warning - # treat missing returns as a warning (not a hint) - missing_return: warning - # allow having TODO comments in the code - todo: ignore # allow self-reference to deprecated members (we do this because otherwise we have # to annotate every member in every test, assert, etc, when we deprecate something) deprecated_member_use_from_same_package: ignore - # Ignore analyzer hints for updating pubspecs when using Future or - # Stream and not importing dart:async - # Please see https://github.com/flutter/flutter/pull/24528 for details. - sdk_version_async_exported_from_core: ignore # Turned off until null-safe rollout is complete. unnecessary_null_comparison: ignore - ### Local flutter/plugins changes ### - # Allow null checks for as long as mixed mode is officially supported. - always_require_non_null_named_parameters: false # not needed with nnbd - exclude: + exclude: # DIFFERENT FROM FLUTTER/FLUTTER # Ignore generated files - '**/*.g.dart' - - 'lib/src/generated/*.dart' - '**/*.mocks.dart' # Mockito @GenerateMocks - - '**/*.pigeon.dart' # Pigeon generated file linter: rules: @@ -54,19 +40,19 @@ linter: - avoid_field_initializers_in_const_classes # - avoid_final_parameters # incompatible with prefer_final_parameters - avoid_function_literals_in_foreach_calls - # - avoid_implementing_value_types # LOCAL CHANGE - Needs to be enabled and violations fixed. + - avoid_implementing_value_types - avoid_init_to_null - avoid_js_rounded_ints # - avoid_multiple_declarations_per_line # seems to be a stylistic choice we don't subscribe to - avoid_null_checks_in_equality_operators # - avoid_positional_boolean_parameters # would have been nice to enable this but by now there's too many places that break it - # - avoid_print # LOCAL CHANGE - Needs to be enabled and violations fixed. + - avoid_print # - avoid_private_typedef_functions # we prefer having typedef (discussion in https://github.com/flutter/flutter/pull/16356) - avoid_redundant_argument_values - avoid_relative_lib_imports - avoid_renaming_method_parameters - avoid_return_types_on_setters - # - avoid_returning_null # still violated by some pre-nnbd code that we haven't yet migrated + - avoid_returning_null - avoid_returning_null_for_future - avoid_returning_null_for_void # - avoid_returning_this # there are enough valid reasons to return `this` that this lint ends up with too many false positives @@ -88,15 +74,17 @@ linter: # - cascade_invocations # doesn't match the typical style of this repo - cast_nullable_to_non_nullable # - close_sinks # not reliable enough + # - combinators_ordering # DIFFERENT FROM FLUTTER/FLUTTER: This isn't available on stable yet. # - comment_references # blocked on https://github.com/dart-lang/linter/issues/1142 - # - conditional_uri_does_not_exist # not yet tested + - conditional_uri_does_not_exist # - constant_identifier_names # needs an opt-out https://github.com/dart-lang/linter/issues/204 - control_flow_in_finally - # - curly_braces_in_flow_control_structures # not required by flutter style - # - depend_on_referenced_packages # LOCAL CHANGE - Needs to be enabled and violations fixed. + - curly_braces_in_flow_control_structures + - depend_on_referenced_packages - deprecated_consistency # - diagnostic_describe_all_properties # enabled only at the framework level (packages/flutter/lib) - directives_ordering + # - discarded_futures # not yet tested # - do_not_use_environment # there are appropriate times to use the environment, especially in our tests and build logic - empty_catches - empty_constructor_bodies @@ -107,7 +95,6 @@ linter: - flutter_style_todos - hash_and_equals - implementation_imports - # - invariant_booleans # too many false positives: https://github.com/dart-lang/linter/issues/811 - iterable_contains_unrelated_type # - join_return_with_assignment # not required by flutter style - leading_newlines_in_multiline_strings @@ -122,7 +109,7 @@ linter: # - no_default_cases # LOCAL CHANGE - Needs to be enabled and violations fixed. - no_duplicate_case_values - no_leading_underscores_for_library_prefixes - # - no_leading_underscores_for_local_identifiers # LOCAL CHANGE - Needs to be enabled and violations fixed. + - no_leading_underscores_for_local_identifiers - no_logic_in_create_state # - no_runtimeType_toString # ok in tests; we enable this only in packages/ - non_constant_identifier_names @@ -172,7 +159,7 @@ linter: # - prefer_mixin # Has false positives, see https://github.com/dart-lang/linter/issues/3018 # - prefer_null_aware_method_calls # "call()" is confusing to people new to the language since it's not documented anywhere - prefer_null_aware_operators - # - prefer_relative_imports # LOCAL CHANGE - Needs to be enabled and violations fixed. + - prefer_relative_imports - prefer_single_quotes - prefer_spread_collections - prefer_typing_uninitialized_variables @@ -182,12 +169,12 @@ linter: - recursive_getters # - require_trailing_commas # blocked on https://github.com/dart-lang/sdk/issues/47441 - secure_pubspec_urls - # - sized_box_for_whitespace # LOCAL CHANGE - Needs to be enabled and violations fixed. + - sized_box_for_whitespace # - sized_box_shrink_expand # not yet tested - slash_for_doc_comments - sort_child_properties_last - sort_constructors_first - # - sort_pub_dependencies # prevents separating pinned transitive dependencies + - sort_pub_dependencies # DIFFERENT FROM FLUTTER/FLUTTER: Flutter's use case for not sorting does not apply to this repository. - sort_unnamed_constructors_first - test_types_in_equals - throw_in_finally @@ -195,7 +182,7 @@ linter: # - type_annotate_public_apis # subset of always_specify_types - type_init_formals # - unawaited_futures # too many false positives, especially with the way AnimationController works - # - unnecessary_await_in_return # LOCAL CHANGE - Needs to be enabled and violations fixed. + - unnecessary_await_in_return - unnecessary_brace_in_string_interps - unnecessary_const - unnecessary_constructor_name @@ -205,6 +192,7 @@ linter: - unnecessary_late - unnecessary_new - unnecessary_null_aware_assignments + - unnecessary_null_aware_operator_on_extension_on_nullable - unnecessary_null_checks - unnecessary_null_in_if_null_operators - unnecessary_nullable_for_final_variable_declarations @@ -215,6 +203,7 @@ linter: - unnecessary_string_escapes - unnecessary_string_interpolations - unnecessary_this + - unnecessary_to_list_in_spreads - unrelated_type_equality_checks - unsafe_html # - use_build_context_synchronously # LOCAL CHANGE - Needs to be enabled and violations fixed. @@ -242,6 +231,3 @@ linter: # separately when moving to a shared file. - no_runtimeType_toString # use objectRuntimeType from package:foundation - public_member_api_docs # see https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#documentation-dartdocs-javadocs-etc - # Flutter has a specific use case for dependencies that are intentionally - # not sorted, which doesn't apply to this repo. - - sort_pub_dependencies diff --git a/analysis_options_plus.yaml b/analysis_options_plus.yaml index 8bb0a7ef6..8aa9d35be 100644 --- a/analysis_options_plus.yaml +++ b/analysis_options_plus.yaml @@ -1,4 +1,5 @@ -# This file was copied from plus_plugins/analysis_options.yaml. +# This file is a copy of analysis_options.yaml from plus_plugins repo +# as of 2023-03-07. include: package:flutter_lints/flutter.yaml diff --git a/packages/camera/example/integration_test/camera_test.dart b/packages/camera/example/integration_test/camera_test.dart index 225e7db33..8e3d3f372 100644 --- a/packages/camera/example/integration_test/camera_test.dart +++ b/packages/camera/example/integration_test/camera_test.dart @@ -48,8 +48,6 @@ void main() { Future testCaptureImageResolution( CameraController controller, ResolutionPreset preset) async { final Size expectedSize = presetExpectedSizes[preset]!; - print( - 'Capturing photo at $preset (${expectedSize.width}x${expectedSize.height}) using camera ${controller.description.name}'); // Take Picture final XFile file = await controller.takePicture(); @@ -93,8 +91,6 @@ void main() { Future testCaptureVideoResolution( CameraController controller, ResolutionPreset preset) async { final Size expectedSize = presetExpectedSizes[preset]!; - print( - 'Capturing video at $preset (${expectedSize.width}x${expectedSize.height}) using camera ${controller.description.name}'); // Take Video await controller.startVideoRecording(); @@ -206,16 +202,16 @@ void main() { ); await controller.initialize(); - bool _isDetecting = false; + bool isDetecting = false; await controller.startImageStream((CameraImage image) { - if (_isDetecting) { + if (isDetecting) { return; } - _isDetecting = true; + isDetecting = true; - expectLater(image, isNotNull).whenComplete(() => _isDetecting = false); + expectLater(image, isNotNull).whenComplete(() => isDetecting = false); }); expect(controller.value.isStreamingImages, true); diff --git a/packages/camera/example/lib/main.dart b/packages/camera/example/lib/main.dart index 9c4c6e827..942af97fb 100644 --- a/packages/camera/example/lib/main.dart +++ b/packages/camera/example/lib/main.dart @@ -37,11 +37,8 @@ IconData getCameraLensIcon(CameraLensDirection direction) { } void _logError(String code, String? message) { - if (message != null) { - print('Error: $code\nError Message: $message'); - } else { - print('Error: $code'); - } + // ignore: avoid_print + print('Error: $code${message == null ? '' : '\nError Message: $message'}'); } class _CameraExampleHomeState extends State diff --git a/packages/device_info_plus/README.md b/packages/device_info_plus/README.md index 7e0738033..05a2d2c33 100644 --- a/packages/device_info_plus/README.md +++ b/packages/device_info_plus/README.md @@ -20,7 +20,8 @@ import 'package:device_info_plus_tizen/device_info_plus_tizen.dart'; DeviceInfoPluginTizen deviceInfo = DeviceInfoPluginTizen(); TizenDeviceInfo tizenInfo = await deviceInfo.tizenInfo; -print('Running on ${tizenInfo.modelName}'); // e.g. "SM-R800" + +String modelName = tizenInfo.modelName; ``` ## Available values diff --git a/packages/firebase_core/example/lib/main.dart b/packages/firebase_core/example/lib/main.dart index 9d4c90ca4..15d8af5ef 100644 --- a/packages/firebase_core/example/lib/main.dart +++ b/packages/firebase_core/example/lib/main.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// ignore_for_file: public_member_api_docs +// ignore_for_file: public_member_api_docs, avoid_print import 'dart:async'; import 'dart:developer'; diff --git a/packages/firebase_core/lib/firebase_core_tizen.dart b/packages/firebase_core/lib/firebase_core_tizen.dart index 517cea792..16ed85965 100644 --- a/packages/firebase_core/lib/firebase_core_tizen.dart +++ b/packages/firebase_core/lib/firebase_core_tizen.dart @@ -56,26 +56,26 @@ class FirebaseCore extends FirebasePlatform { /// Ensures the name isn't null, in case no name /// passed, [defaultFirebaseAppName] will be used - final String _name = name ?? defaultFirebaseAppName; + name ??= defaultFirebaseAppName; try { // Initialize the app in firebase_core_dart - final core_dart.FirebaseOptions _dartOptions = + final core_dart.FirebaseOptions dartOptions = core_dart.FirebaseOptions.fromMap(options!.asMap); - final core_dart.FirebaseApp _dartApp = + final core_dart.FirebaseApp dartApp = await core_dart.Firebase.initializeApp( - name: _name, - options: _dartOptions, + name: name, + options: dartOptions, ); - return _mapDartToPlatfromApp(_dartApp); + return _mapDartToPlatfromApp(dartApp); } on core_dart.FirebaseException catch (e) { switch (e.code) { case 'no-app': - throw noAppExists(_name); + throw noAppExists(name); case 'duplicate-app': - throw duplicateApp(_name); + throw duplicateApp(name); } rethrow; diff --git a/packages/google_maps_flutter/example/lib/map_coordinates.dart b/packages/google_maps_flutter/example/lib/map_coordinates.dart index 12e31be8f..efb4a105f 100644 --- a/packages/google_maps_flutter/example/lib/map_coordinates.dart +++ b/packages/google_maps_flutter/example/lib/map_coordinates.dart @@ -72,7 +72,7 @@ class _MapCoordinatesBodyState extends State<_MapCoordinatesBody> { // Add a block at the bottom of this list to allow validation that the visible region of the map // does not change when scrolled under the safe view on iOS. // https://github.com/flutter/flutter/issues/107913 - Container( + const SizedBox( width: 300, height: 1000, ), diff --git a/packages/google_maps_flutter/example/pubspec.yaml b/packages/google_maps_flutter/example/pubspec.yaml index e9cf14426..1c318c217 100644 --- a/packages/google_maps_flutter/example/pubspec.yaml +++ b/packages/google_maps_flutter/example/pubspec.yaml @@ -10,6 +10,7 @@ dependencies: flutter: sdk: flutter google_maps_flutter: ^2.1.7 + google_maps_flutter_platform_interface: ^2.1.2 google_maps_flutter_tizen: path: ../ diff --git a/packages/google_maps_flutter/lib/src/circle.dart b/packages/google_maps_flutter/lib/src/circle.dart index 70aa6dd3b..a65f666bc 100644 --- a/packages/google_maps_flutter/lib/src/circle.dart +++ b/packages/google_maps_flutter/lib/src/circle.dart @@ -25,10 +25,10 @@ class CircleController { /// Circle component's tap event. ui.VoidCallback? tapEvent; - Future _addCircleEvent(Future? _controller) async { + Future _addCircleEvent(Future? controller) async { final String command = "$_circle.addListener('click', (event) => CircleClick.postMessage(JSON.stringify(${_circle?.id})));"; - await (await _controller!).runJavascript(command); + await (await controller!).runJavascript(command); } /// Returns `true` if this Controller will use its own `onTap` handler to consume events. diff --git a/packages/google_maps_flutter/lib/src/convert.dart b/packages/google_maps_flutter/lib/src/convert.dart index 4a9a3c17e..637fe70ac 100644 --- a/packages/google_maps_flutter/lib/src/convert.dart +++ b/packages/google_maps_flutter/lib/src/convert.dart @@ -171,7 +171,7 @@ LatLngBounds _convertToBounds(String value) { northeast: LatLng(bound['north'] as double, bound['east'] as double)); } } catch (e) { - print('Javascript Error: $e'); + debugPrint('Javascript Error: $e'); } return util.nullLatLngBounds; } @@ -184,7 +184,7 @@ LatLng _convertToLatLng(String value) { return LatLng((latlng['lat'] as num) + 0.0, (latlng['lng'] as num) + 0.0); } } catch (e) { - print('Javascript Error: $e'); + debugPrint('Javascript Error: $e'); } return util.nullLatLng; } @@ -205,7 +205,7 @@ ScreenCoordinate _convertToPoint(String value) { return ScreenCoordinate(x: x, y: y); } } catch (e) { - print('Javascript Error: $e'); + debugPrint('Javascript Error: $e'); } return util.nullScreenCoordinate; } @@ -324,12 +324,10 @@ util.GPolygonOptions _polygonOptionsFromPolygon(Polygon polygon) { List holePath = polygon.holes[i]; if (_isPolygonClockwise(holePath) == polygonDirection) { holePath = holePath.reversed.toList(); - if (kDebugMode) { - print( - 'Hole [$holeIndex] in Polygon [${polygon.polygonId.value}] has been reversed.' - ' Ensure holes in polygons are "wound in the opposite direction to the outer path."' - ' More info: https://github.com/flutter/flutter/issues/74096'); - } + debugPrint( + 'Hole [$holeIndex] in Polygon [${polygon.polygonId.value}] has been reversed.' + ' Ensure holes in polygons are "wound in the opposite direction to the outer path."' + ' More info: https://github.com/flutter/flutter/issues/74096'); } paths.add(holePath); holeIndex++; diff --git a/packages/google_maps_flutter/lib/src/google_maps_controller.dart b/packages/google_maps_flutter/lib/src/google_maps_controller.dart index 314dd6c89..d713e8bad 100644 --- a/packages/google_maps_flutter/lib/src/google_maps_controller.dart +++ b/packages/google_maps_flutter/lib/src/google_maps_controller.dart @@ -229,7 +229,7 @@ class GoogleMapsController { _streamController.add(MapReadyEvent(_mapId)); _isFirst = true; } catch (e) { - print('Javascript Error: $e'); + debugPrint('Javascript Error: $e'); } }); } @@ -250,7 +250,7 @@ class GoogleMapsController { _streamController.add(MapTapEvent(_mapId, position)); } } catch (e) { - print('Javascript Error: $e'); + debugPrint('Javascript Error: $e'); } }); } @@ -272,7 +272,7 @@ class GoogleMapsController { _streamController.add(MapLongPressEvent(_mapId, position)); } } catch (e) { - print('Javascript Error: $e'); + debugPrint('Javascript Error: $e'); } }); } @@ -295,7 +295,7 @@ class GoogleMapsController { } } } catch (e) { - print('Javascript Error: $e'); + debugPrint('Javascript Error: $e'); } }); } @@ -327,7 +327,7 @@ class GoogleMapsController { } } } catch (e) { - print('Javascript Error: $e'); + debugPrint('Javascript Error: $e'); } }); } @@ -351,7 +351,7 @@ class GoogleMapsController { } } } catch (e) { - print('Javascript Error: $e'); + debugPrint('Javascript Error: $e'); } }); } @@ -375,7 +375,7 @@ class GoogleMapsController { } } } catch (e) { - print('Javascript Error: $e'); + debugPrint('Javascript Error: $e'); } }); } @@ -398,7 +398,7 @@ class GoogleMapsController { } } } catch (e) { - print('Javascript Error: $e'); + debugPrint('Javascript Error: $e'); } }); } @@ -534,7 +534,7 @@ class GoogleMapsController { Future _callMethod( WebViewController mapView, String method, List args) async { - return await mapView.runJavascriptReturningResult( + return mapView.runJavascriptReturningResult( 'JSON.stringify(map.$method.apply(map, $args))'); } @@ -542,7 +542,7 @@ class GoogleMapsController { try { return double.parse(await _callMethod(c, 'getZoom', [])); } catch (e) { - print('Javascript Error: $e'); + debugPrint('Javascript Error: $e'); return 0.0; } } @@ -614,7 +614,7 @@ class GoogleMapsController { focusLatLng = await _pixelToLatLng( json[2][0] as double, json[2][1] as double); } catch (e) { - print('Error computing focus LatLng. JS Error: $e'); + debugPrint('Error computing focus LatLng. JS Error: $e'); } } await _setZoom('${(await getZoomLevel()) + newZoomDelta}'); @@ -651,7 +651,7 @@ class GoogleMapsController { JSON.stringify(getPixelToLatLng()); '''; - return await (await controller).runJavascriptReturningResult(command); + return (await controller).runJavascriptReturningResult(command); } Future _latLngToPoint(LatLng latLng) async { @@ -671,12 +671,12 @@ class GoogleMapsController { JSON.stringify(getLatLngToPixel()); '''; - return await (await controller).runJavascriptReturningResult(command); + return (await controller).runJavascriptReturningResult(command); } /// Returns the zoom level of the current viewport. Future getZoomLevel() async { - return await _getZoom(await controller); + return _getZoom(await controller); } // Geometry manipulation diff --git a/packages/google_maps_flutter/lib/src/marker.dart b/packages/google_maps_flutter/lib/src/marker.dart index ca4a1e789..9ed731095 100644 --- a/packages/google_maps_flutter/lib/src/marker.dart +++ b/packages/google_maps_flutter/lib/src/marker.dart @@ -40,11 +40,11 @@ class MarkerController { /// Marker component's drag end event. LatLngCallback? dragEndEvent; - Future _addMarkerEvent(Future? _controller) async { + Future _addMarkerEvent(Future? controller) async { final String command = ''' $marker.addListener("click", (event) => MarkerClick.postMessage(JSON.stringify(${marker?.id}))); $marker.addListener("dragend", (event) => MarkerDragEnd.postMessage(JSON.stringify({id:${marker?.id}, event:event})));'''; - await (await _controller!).runJavascript(command); + await (await controller!).runJavascript(command); } /// Returns `true` if this Controller will use its own `onTap` handler to consume events. diff --git a/packages/google_maps_flutter/lib/src/polygon.dart b/packages/google_maps_flutter/lib/src/polygon.dart index 24dd61e22..b776c3cc6 100644 --- a/packages/google_maps_flutter/lib/src/polygon.dart +++ b/packages/google_maps_flutter/lib/src/polygon.dart @@ -25,10 +25,10 @@ class PolygonController { /// Polygon component's tap event. ui.VoidCallback? tapEvent; - Future _addPolygonEvent(Future? _controller) async { + Future _addPolygonEvent(Future? controller) async { final String command = "$_polygon.addListener('click', (event) => PolygonClick.postMessage(JSON.stringify(${_polygon?.id})));"; - await (await _controller!).runJavascript(command); + await (await controller!).runJavascript(command); } /// Returns `true` if this Controller will use its own `onTap` handler to consume events. diff --git a/packages/google_maps_flutter/lib/src/polyline.dart b/packages/google_maps_flutter/lib/src/polyline.dart index 9b607878f..1a4ada3c8 100644 --- a/packages/google_maps_flutter/lib/src/polyline.dart +++ b/packages/google_maps_flutter/lib/src/polyline.dart @@ -25,10 +25,10 @@ class PolylineController { /// Polyline component's tap event. ui.VoidCallback? tapEvent; - Future _addPolylineEvent(Future? _controller) async { + Future _addPolylineEvent(Future? controller) async { final String command = "$_polyline.addListener('click', (event) => PolylineClick.postMessage(JSON.stringify(${_polyline?.id})));"; - await (await _controller!).runJavascript(command); + await (await controller!).runJavascript(command); } /// Returns `true` if this Controller will use its own `onTap` handler to consume events. diff --git a/packages/google_maps_flutter/lib/src/util.dart b/packages/google_maps_flutter/lib/src/util.dart index 0f0c3cd95..c28f9bc0d 100644 --- a/packages/google_maps_flutter/lib/src/util.dart +++ b/packages/google_maps_flutter/lib/src/util.dart @@ -564,19 +564,19 @@ Future? webController; Future getProperty(Object o, String property) async { assert(webController != null, 'mapController is null!!'); final String command = "JSON.stringify($o['$property'])"; - return await (await webController!).runJavascriptReturningResult(command); + return (await webController!).runJavascriptReturningResult(command); } /// Sets the value to property of the object. Future setProperty(Object o, String property, Object? value) async { assert(webController != null, 'mapController is null!!'); final String command = "JSON.stringify($o['$property'] = $value)"; - return await (await webController!).runJavascriptReturningResult(command); + return (await webController!).runJavascriptReturningResult(command); } /// Calls the method of the object with the args. Future callMethod(Object o, String method, List args) async { assert(webController != null, 'webController is null!!'); final String command = 'JSON.stringify($o.$method.apply($o, $args))'; - return await (await webController!).runJavascriptReturningResult(command); + return (await webController!).runJavascriptReturningResult(command); } diff --git a/packages/google_sign_in/example/lib/main.dart b/packages/google_sign_in/example/lib/main.dart index 92ef5ced2..41cd7ec2d 100644 --- a/packages/google_sign_in/example/lib/main.dart +++ b/packages/google_sign_in/example/lib/main.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// ignore_for_file: public_member_api_docs +// ignore_for_file: public_member_api_docs, avoid_print import 'dart:async'; import 'dart:convert' show json; diff --git a/packages/image_picker/example/lib/main.dart b/packages/image_picker/example/lib/main.dart index 33727219c..3f59b781f 100644 --- a/packages/image_picker/example/lib/main.dart +++ b/packages/image_picker/example/lib/main.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// ignore_for_file: public_member_api_docs +// ignore_for_file: public_member_api_docs, avoid_print import 'dart:async'; import 'dart:io'; diff --git a/packages/messageport/README.md b/packages/messageport/README.md index a9b6b49db..9e1bf25e9 100644 --- a/packages/messageport/README.md +++ b/packages/messageport/README.md @@ -25,7 +25,7 @@ To register callback to be called when message arrives to the local port, use `L ```dart void onMessage(Object message, [RemotePort remotePort]) { - print('Message received: $message'); + // Handle the received message. } ... localPort.register(onMessage); @@ -53,11 +53,7 @@ To send message to remote applcation, use `RemotePort.send()` method. ```dart final message = {'a': 1, 'b': 2, 'c': 3}; -try{ - await remotePort.send(message); -} catch (error) { - print('Could not send message: $error'); -} +await remotePort.send(message); ``` ### Send message with local port @@ -66,11 +62,7 @@ To send message with local port information, use `RemotePort.send()` method. Loc ```dart final message = 'This is a string message'; -try{ - await remotePort.sendWithLocalPort(message, localPort); -} catch (error) { - print('Could not send message: $error'); -} +await remotePort.sendWithLocalPort(message, localPort); ``` ### Supported data types diff --git a/packages/messageport/example/integration_test/messageport_test.dart b/packages/messageport/example/integration_test/messageport_test.dart index d521ab5bb..bd7fe48c8 100644 --- a/packages/messageport/example/integration_test/messageport_test.dart +++ b/packages/messageport/example/integration_test/messageport_test.dart @@ -76,9 +76,7 @@ void main() { final LocalPort localPort = await LocalPort.create(kTestPort); final Completer> completer = Completer>(); localPort.register((dynamic message, [RemotePort? remotePort]) { - if (completer.isCompleted) { - print('WARNING: additional message received: $message'); - } else { + if (!completer.isCompleted) { completer.complete([message, remotePort]); } }); diff --git a/packages/path_provider/example/integration_test/path_provider_test.dart b/packages/path_provider/example/integration_test/path_provider_test.dart index 749a49854..bb723d2d8 100644 --- a/packages/path_provider/example/integration_test/path_provider_test.dart +++ b/packages/path_provider/example/integration_test/path_provider_test.dart @@ -58,7 +58,7 @@ void main() { } }); - final List _allDirs = [ + final List allDirs = [ null, StorageDirectory.music, StorageDirectory.podcasts, @@ -68,7 +68,7 @@ void main() { StorageDirectory.movies, ]; - for (final StorageDirectory? type in _allDirs) { + for (final StorageDirectory? type in allDirs) { test('getExternalStorageDirectories (type: $type)', () async { if (Platform.isIOS) { final Future?> result = getExternalStorageDirectories(); diff --git a/packages/shared_preferences/lib/shared_preferences_tizen.dart b/packages/shared_preferences/lib/shared_preferences_tizen.dart index a7b919147..95f976561 100644 --- a/packages/shared_preferences/lib/shared_preferences_tizen.dart +++ b/packages/shared_preferences/lib/shared_preferences_tizen.dart @@ -120,8 +120,7 @@ class SharedPreferencesPlugin extends SharedPreferencesStorePlatform { .toNativeChar(allocator: arena), ); default: - print('Not implemented: valueType[$valueType]'); - return -1; + throw UnimplementedError('Not supported type: $valueType'); } }); if (ret == 0) { diff --git a/packages/tizen_app_manager/README.md b/packages/tizen_app_manager/README.md index 6ac2188be..e0608d5c1 100644 --- a/packages/tizen_app_manager/README.md +++ b/packages/tizen_app_manager/README.md @@ -50,7 +50,7 @@ You can listen for app state changes by subscribing to `AppManager.onAppLaunched ```dart var subscription = AppManager.onAppLaunched.listen((AppRunningContext context) { - print('Launched ${context.appId}'); + String appId = context.appId; }); ... subscription.cancel(); diff --git a/packages/tizen_app_manager/example/lib/main.dart b/packages/tizen_app_manager/example/lib/main.dart index 2efaadad9..8a130b89b 100644 --- a/packages/tizen_app_manager/example/lib/main.dart +++ b/packages/tizen_app_manager/example/lib/main.dart @@ -84,7 +84,7 @@ class _CurrentAppScreen extends StatefulWidget { class _CurrentAppScreenState extends State<_CurrentAppScreen> { final Future _appInfo = () async { final String appId = await AppManager.currentAppId; - return await AppManager.getAppInfo(appId); + return AppManager.getAppInfo(appId); }(); Widget _infoTile(String title, String subtitle) { diff --git a/packages/tizen_audio_manager/README.md b/packages/tizen_audio_manager/README.md index e89db9a1c..2f7c8bc82 100644 --- a/packages/tizen_audio_manager/README.md +++ b/packages/tizen_audio_manager/README.md @@ -40,9 +40,10 @@ You can detect volume changes using `AudioManager.volumeController.onChanged`. ```dart _subscription = AudioManager.volumeController.onChanged.listen((event) { - final mediaType = event.type; - final newLevel = event.level; + final mediaType = event.type; + final newLevel = event.level; }); +... _subscription.cancel(); ``` @@ -51,8 +52,7 @@ _subscription.cancel(); Use the following code to get currently playing playback type: ```dart -final type = await AudioManager.volumeController.currentPlaybackType; -print(type); +final playbackType = await AudioManager.volumeController.currentPlaybackType; ``` ### Available types diff --git a/packages/tizen_bundle/README.md b/packages/tizen_bundle/README.md index 21b04a2c0..110a69ff6 100644 --- a/packages/tizen_bundle/README.md +++ b/packages/tizen_bundle/README.md @@ -35,17 +35,17 @@ To get data from a bundle or update their values, use the `[]` operator. ```dart var stringValue = bundle['string']; if (stringValue is String) { - print('string: $stringValue'); + // The value is a string. } var stringsValue = bundle['strings']; if (stringsValue is List) { - print('strings: $stringsValue'); + // The value is a string list. } var bytesValue = bundle['bytes']; if (bytesValue is Uint8List) { - print('bytes: $bytesValue'); + // The value is a byte list. } ``` @@ -67,6 +67,4 @@ bundle['key'] = 'value'; var encoded = bundle.encode(); var newBundle = Bundle.decode(encoded); - -print(newBundle['key']); ``` diff --git a/packages/tizen_rpc_port/example/client/lib/message_client.dart b/packages/tizen_rpc_port/example/client/lib/message_client.dart index f8ee0ee55..bc6e466ec 100644 --- a/packages/tizen_rpc_port/example/client/lib/message_client.dart +++ b/packages/tizen_rpc_port/example/client/lib/message_client.dart @@ -102,9 +102,8 @@ class Message extends ProxyBase { final Parcel parcel = Parcel.fromPort(port); final int cmd = parcel.readInt32(); if (cmd != _MethodId.result.id) { - print('Received parcel is invalid. $cmd'); + throw Exception('The received parcel is invalid ($cmd).'); } - return parcel; } diff --git a/packages/tizen_rpc_port/example/server/lib/main.dart b/packages/tizen_rpc_port/example/server/lib/main.dart index 1a2e60475..cb2233c36 100644 --- a/packages/tizen_rpc_port/example/server/lib/main.dart +++ b/packages/tizen_rpc_port/example/server/lib/main.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// ignore_for_file: public_member_api_docs +// ignore_for_file: public_member_api_docs, avoid_print import 'dart:async'; diff --git a/packages/tizen_rpc_port/lib/src/proxy_base.dart b/packages/tizen_rpc_port/lib/src/proxy_base.dart index bc62f5bb9..aac230107 100644 --- a/packages/tizen_rpc_port/lib/src/proxy_base.dart +++ b/packages/tizen_rpc_port/lib/src/proxy_base.dart @@ -6,6 +6,7 @@ import 'dart:async'; import 'dart:ffi'; import 'package:ffi/ffi.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:tizen_interop/6.5/tizen.dart'; @@ -122,7 +123,7 @@ abstract class ProxyBase { final Parcel parcel = Parcel.fromRaw(rawData); await onReceivedEvent(parcel); } else { - print('Unknown event: $event'); + debugPrint('Unknown event: $event'); } }, onError: onError); diff --git a/packages/tizen_rpc_port/lib/src/stub_base.dart b/packages/tizen_rpc_port/lib/src/stub_base.dart index 4eeb75dbc..44234da01 100644 --- a/packages/tizen_rpc_port/lib/src/stub_base.dart +++ b/packages/tizen_rpc_port/lib/src/stub_base.dart @@ -6,6 +6,7 @@ import 'dart:async'; import 'dart:ffi'; import 'package:ffi/ffi.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:tizen_interop/6.5/tizen.dart'; @@ -101,7 +102,7 @@ abstract class StubBase { final Parcel parcel = Parcel.fromRaw(rawData); await onReceivedEvent(sender, instance, parcel); } else { - print('Unknown event: $event'); + debugPrint('Unknown event: $event'); } }, onError: onError); } diff --git a/packages/url_launcher/example/lib/main.dart b/packages/url_launcher/example/lib/main.dart index a538940f1..a870e18a5 100644 --- a/packages/url_launcher/example/lib/main.dart +++ b/packages/url_launcher/example/lib/main.dart @@ -196,7 +196,6 @@ class _MyHomePageState extends State { onPressed: () => setState(() { _launched = _launchInWebViewOrVC(toLaunch); Timer(const Duration(seconds: 5), () { - print('Closing WebView after 5 seconds...'); closeInAppWebView(); }); }), diff --git a/packages/video_player/example/integration_test/video_player_test.dart b/packages/video_player/example/integration_test/video_player_test.dart index 76a284af1..d249847e0 100644 --- a/packages/video_player/example/integration_test/video_player_test.dart +++ b/packages/video_player/example/integration_test/video_player_test.dart @@ -34,22 +34,22 @@ String getUrlForAssetAsNetworkSource(String assetKey) { void main() { IntegrationTestWidgetsFlutterBinding.ensureInitialized(); - late VideoPlayerController _controller; - tearDown(() async => _controller.dispose()); + late VideoPlayerController controller; + tearDown(() async => controller.dispose()); group('asset videos', () { setUp(() { - _controller = VideoPlayerController.asset(_videoAssetKey); + controller = VideoPlayerController.asset(_videoAssetKey); }); testWidgets('can be initialized', (WidgetTester tester) async { - await _controller.initialize(); + await controller.initialize(); - expect(_controller.value.isInitialized, true); - expect(_controller.value.position, Duration.zero); - expect(_controller.value.isPlaying, false); + expect(controller.value.isInitialized, true); + expect(controller.value.position, Duration.zero); + expect(controller.value.isPlaying, false); // The WebM version has a slightly different duration than the MP4. - expect(_controller.value.duration, + expect(controller.value.duration, const Duration(seconds: 7, milliseconds: kIsWeb ? 544 : 540)); }); @@ -74,16 +74,16 @@ void main() { testWidgets( 'can be played', (WidgetTester tester) async { - await _controller.initialize(); + await controller.initialize(); // Mute to allow playing without DOM interaction on Web. // See https://developers.google.com/web/updates/2017/09/autoplay-policy-changes - await _controller.setVolume(0); + await controller.setVolume(0); - await _controller.play(); + await controller.play(); await tester.pumpAndSettle(_playDuration); - expect(_controller.value.isPlaying, true); - expect(_controller.value.position, + expect(controller.value.isPlaying, true); + expect(controller.value.position, (Duration position) => position > Duration.zero); }, ); @@ -91,85 +91,85 @@ void main() { testWidgets( 'can seek', (WidgetTester tester) async { - await _controller.initialize(); + await controller.initialize(); - await _controller.seekTo(const Duration(seconds: 3)); + await controller.seekTo(const Duration(seconds: 3)); - expect(_controller.value.position, const Duration(seconds: 3)); + expect(controller.value.position, const Duration(seconds: 3)); }, ); testWidgets( 'can be paused', (WidgetTester tester) async { - await _controller.initialize(); + await controller.initialize(); // Mute to allow playing without DOM interaction on Web. // See https://developers.google.com/web/updates/2017/09/autoplay-policy-changes - await _controller.setVolume(0); + await controller.setVolume(0); // Play for a second, then pause, and then wait a second. - await _controller.play(); + await controller.play(); await tester.pumpAndSettle(_playDuration); - await _controller.pause(); - final Duration pausedPosition = _controller.value.position; + await controller.pause(); + final Duration pausedPosition = controller.value.position; await tester.pumpAndSettle(_playDuration); // Verify that we stopped playing after the pause. - expect(_controller.value.isPlaying, false); - expect(_controller.value.position, pausedPosition); + expect(controller.value.isPlaying, false); + expect(controller.value.position, pausedPosition); }, ); testWidgets( 'stay paused when seeking after video completed', (WidgetTester tester) async { - await _controller.initialize(); + await controller.initialize(); // Mute to allow playing without DOM interaction on Web. // See https://developers.google.com/web/updates/2017/09/autoplay-policy-changes - await _controller.setVolume(0); + await controller.setVolume(0); final Duration timeBeforeEnd = - _controller.value.duration - const Duration(milliseconds: 500); - await _controller.seekTo(timeBeforeEnd); - await _controller.play(); + controller.value.duration - const Duration(milliseconds: 500); + await controller.seekTo(timeBeforeEnd); + await controller.play(); await tester.pumpAndSettle(_playDuration); - expect(_controller.value.isPlaying, false); - expect(_controller.value.position, _controller.value.duration); + expect(controller.value.isPlaying, false); + expect(controller.value.position, controller.value.duration); - await _controller.seekTo(timeBeforeEnd); + await controller.seekTo(timeBeforeEnd); await tester.pumpAndSettle(_playDuration); - expect(_controller.value.isPlaying, false); - expect(_controller.value.position, timeBeforeEnd); + expect(controller.value.isPlaying, false); + expect(controller.value.position, timeBeforeEnd); }, ); testWidgets( 'do not exceed duration on play after video completed', (WidgetTester tester) async { - await _controller.initialize(); + await controller.initialize(); // Mute to allow playing without DOM interaction on Web. // See https://developers.google.com/web/updates/2017/09/autoplay-policy-changes - await _controller.setVolume(0); - await _controller.seekTo( - _controller.value.duration - const Duration(milliseconds: 500)); - await _controller.play(); + await controller.setVolume(0); + await controller.seekTo( + controller.value.duration - const Duration(milliseconds: 500)); + await controller.play(); await tester.pumpAndSettle(_playDuration); - expect(_controller.value.isPlaying, false); - expect(_controller.value.position, _controller.value.duration); + expect(controller.value.isPlaying, false); + expect(controller.value.position, controller.value.duration); - await _controller.play(); + await controller.play(); await tester.pumpAndSettle(_playDuration); - expect(_controller.value.position, - lessThanOrEqualTo(_controller.value.duration)); + expect(controller.value.position, + lessThanOrEqualTo(controller.value.duration)); }, ); testWidgets('test video player view with local asset', (WidgetTester tester) async { Future started() async { - await _controller.initialize(); - await _controller.play(); + await controller.initialize(); + await controller.play(); return true; } @@ -182,8 +182,8 @@ void main() { builder: (BuildContext context, AsyncSnapshot snapshot) { if (snapshot.data ?? false) { return AspectRatio( - aspectRatio: _controller.value.aspectRatio, - child: VideoPlayer(_controller), + aspectRatio: controller.value.aspectRatio, + child: VideoPlayer(controller), ); } else { return const Text('waiting for video to load'); @@ -195,7 +195,7 @@ void main() { )); await tester.pumpAndSettle(); - expect(_controller.value.isPlaying, true); + expect(controller.value.isPlaying, true); }, skip: kIsWeb || // Web does not support local assets. // Extremely flaky on iOS: https://github.com/flutter/flutter/issues/86915 @@ -213,54 +213,54 @@ void main() { final File file = File('$tempDir/$filename'); await file.writeAsBytes(bytes.buffer.asInt8List()); - _controller = VideoPlayerController.file(file); + controller = VideoPlayerController.file(file); }); testWidgets('test video player using static file() method as constructor', (WidgetTester tester) async { - await _controller.initialize(); + await controller.initialize(); - await _controller.play(); - expect(_controller.value.isPlaying, true); + await controller.play(); + expect(controller.value.isPlaying, true); - await _controller.pause(); - expect(_controller.value.isPlaying, false); + await controller.pause(); + expect(controller.value.isPlaying, false); }, skip: kIsWeb); }); group('network videos', () { setUp(() { - _controller = VideoPlayerController.network( + controller = VideoPlayerController.network( getUrlForAssetAsNetworkSource(_videoAssetKey)); }); testWidgets( 'reports buffering status', (WidgetTester tester) async { - await _controller.initialize(); + await controller.initialize(); // Mute to allow playing without DOM interaction on Web. // See https://developers.google.com/web/updates/2017/09/autoplay-policy-changes - await _controller.setVolume(0); + await controller.setVolume(0); final Completer started = Completer(); final Completer ended = Completer(); - _controller.addListener(() { - if (!started.isCompleted && _controller.value.isBuffering) { + controller.addListener(() { + if (!started.isCompleted && controller.value.isBuffering) { started.complete(); } if (started.isCompleted && - !_controller.value.isBuffering && + !controller.value.isBuffering && !ended.isCompleted) { ended.complete(); } }); - await _controller.play(); - await _controller.seekTo(const Duration(seconds: 5)); + await controller.play(); + await controller.seekTo(const Duration(seconds: 5)); await tester.pumpAndSettle(_playDuration); - await _controller.pause(); + await controller.pause(); - expect(_controller.value.isPlaying, false); - expect(_controller.value.position, + expect(controller.value.isPlaying, false); + expect(controller.value.position, (Duration position) => position > Duration.zero); await expectLater(started.future, completes); @@ -274,63 +274,63 @@ void main() { // but could be removed in the future. group('asset audios', () { setUp(() { - _controller = VideoPlayerController.asset('assets/Audio.mp3'); + controller = VideoPlayerController.asset('assets/Audio.mp3'); }); testWidgets('can be initialized', (WidgetTester tester) async { - await _controller.initialize(); + await controller.initialize(); - expect(_controller.value.isInitialized, true); - expect(_controller.value.position, Duration.zero); - expect(_controller.value.isPlaying, false); + expect(controller.value.isInitialized, true); + expect(controller.value.position, Duration.zero); + expect(controller.value.isPlaying, false); // Due to the duration calculation accurancy between platforms, // the milliseconds on Web will be a slightly different from natives. // The audio was made with 44100 Hz, 192 Kbps CBR, and 32 bits. expect( - _controller.value.duration, + controller.value.duration, const Duration(seconds: 5, milliseconds: kIsWeb ? 42 : 41), ); }); testWidgets('can be played', (WidgetTester tester) async { - await _controller.initialize(); + await controller.initialize(); // Mute to allow playing without DOM interaction on Web. // See https://developers.google.com/web/updates/2017/09/autoplay-policy-changes - await _controller.setVolume(0); + await controller.setVolume(0); - await _controller.play(); + await controller.play(); await tester.pumpAndSettle(_playDuration); - expect(_controller.value.isPlaying, true); + expect(controller.value.isPlaying, true); expect( - _controller.value.position, + controller.value.position, (Duration position) => position > Duration.zero, ); }); testWidgets('can seek', (WidgetTester tester) async { - await _controller.initialize(); - await _controller.seekTo(const Duration(seconds: 3)); + await controller.initialize(); + await controller.seekTo(const Duration(seconds: 3)); - expect(_controller.value.position, const Duration(seconds: 3)); + expect(controller.value.position, const Duration(seconds: 3)); }); testWidgets('can be paused', (WidgetTester tester) async { - await _controller.initialize(); + await controller.initialize(); // Mute to allow playing without DOM interaction on Web. // See https://developers.google.com/web/updates/2017/09/autoplay-policy-changes - await _controller.setVolume(0); + await controller.setVolume(0); // Play for a second, then pause, and then wait a second. - await _controller.play(); + await controller.play(); await tester.pumpAndSettle(_playDuration); - await _controller.pause(); - final Duration pausedPosition = _controller.value.position; + await controller.pause(); + final Duration pausedPosition = controller.value.position; await tester.pumpAndSettle(_playDuration); // Verify that we stopped playing after the pause. - expect(_controller.value.isPlaying, false); - expect(_controller.value.position, pausedPosition); + expect(controller.value.isPlaying, false); + expect(controller.value.position, pausedPosition); }); }); } diff --git a/packages/wearable_rotary/lib/src/rotary_scroll_controller.dart b/packages/wearable_rotary/lib/src/rotary_scroll_controller.dart index fddbfb83f..7533d41d2 100644 --- a/packages/wearable_rotary/lib/src/rotary_scroll_controller.dart +++ b/packages/wearable_rotary/lib/src/rotary_scroll_controller.dart @@ -2,7 +2,8 @@ import 'dart:async'; import 'dart:math'; import 'package:flutter/material.dart'; -import 'package:wearable_rotary/wearable_rotary.dart'; + +import 'wearable_rotary_base.dart'; /// A [ScrollController] that responds to [RotaryEvent]s. class RotaryScrollController extends ScrollController { diff --git a/packages/webview_flutter/example/integration_test/webview_flutter_test.dart b/packages/webview_flutter/example/integration_test/webview_flutter_test.dart index 73827ce66..c3710f944 100644 --- a/packages/webview_flutter/example/integration_test/webview_flutter_test.dart +++ b/packages/webview_flutter/example/integration_test/webview_flutter_test.dart @@ -18,8 +18,6 @@ import 'package:webview_flutter/webview_flutter.dart'; Future main() async { IntegrationTestWidgetsFlutterBinding.ensureInitialized(); - const bool _skipDueToIssue86757 = true; - final HttpServer server = await HttpServer.bind(InternetAddress.anyIPv4, 0); server.forEach((HttpRequest request) { if (request.uri.path == '/hello.txt') { @@ -39,10 +37,10 @@ Future main() async { final String primaryUrl = '$prefixUrl/hello.txt'; final String secondaryUrl = '$prefixUrl/secondary.txt'; - // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757 testWidgets('initialUrl', (WidgetTester tester) async { final Completer controllerCompleter = Completer(); + final Completer pageFinishedCompleter = Completer(); await tester.pumpWidget( Directionality( textDirection: TextDirection.ltr, @@ -52,18 +50,22 @@ Future main() async { onWebViewCreated: (WebViewController controller) { controllerCompleter.complete(controller); }, + onPageFinished: pageFinishedCompleter.complete, ), ), ); + final WebViewController controller = await controllerCompleter.future; + await pageFinishedCompleter.future; + final String? currentUrl = await controller.currentUrl(); expect(currentUrl, primaryUrl); - }, skip: _skipDueToIssue86757); + }); - // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757 testWidgets('loadUrl', (WidgetTester tester) async { final Completer controllerCompleter = Completer(); + final StreamController pageLoads = StreamController(); await tester.pumpWidget( Directionality( textDirection: TextDirection.ltr, @@ -73,14 +75,20 @@ Future main() async { onWebViewCreated: (WebViewController controller) { controllerCompleter.complete(controller); }, + onPageFinished: (String url) { + pageLoads.add(url); + }, ), ), ); final WebViewController controller = await controllerCompleter.future; + await controller.loadUrl(secondaryUrl); - final String? currentUrl = await controller.currentUrl(); - expect(currentUrl, secondaryUrl); - }, skip: _skipDueToIssue86757); + await expectLater( + pageLoads.stream.firstWhere((String url) => url == secondaryUrl), + completion(secondaryUrl), + ); + }); testWidgets('evaluateJavascript', (WidgetTester tester) async { final Completer controllerCompleter = @@ -104,13 +112,12 @@ Future main() async { expect(result, equals('2')); }); - // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757 testWidgets('JavascriptChannel', (WidgetTester tester) async { final Completer controllerCompleter = Completer(); final Completer pageStarted = Completer(); final Completer pageLoaded = Completer(); - final List messagesReceived = []; + final Completer channelCompleter = Completer(); await tester.pumpWidget( Directionality( textDirection: TextDirection.ltr, @@ -127,7 +134,7 @@ Future main() async { JavascriptChannel( name: 'Echo', onMessageReceived: (JavascriptMessage message) { - messagesReceived.add(message.message); + channelCompleter.complete(message.message); }, ), }, @@ -144,10 +151,11 @@ Future main() async { await pageStarted.future; await pageLoaded.future; - expect(messagesReceived, isEmpty); + expect(channelCompleter.isCompleted, isFalse); await controller.runJavascript('Echo.postMessage("hello");'); - expect(messagesReceived, equals(['hello'])); - }, skip: Platform.isAndroid && _skipDueToIssue86757); + + await expectLater(channelCompleter.future, completion('hello')); + }); testWidgets('resize webview', (WidgetTester tester) async { final Completer initialResizeCompleter = Completer(); @@ -181,12 +189,12 @@ Future main() async { testWidgets('set custom userAgent', (WidgetTester tester) async { final Completer controllerCompleter1 = Completer(); - final GlobalKey _globalKey = GlobalKey(); + final GlobalKey globalKey = GlobalKey(); await tester.pumpWidget( Directionality( textDirection: TextDirection.ltr, child: WebView( - key: _globalKey, + key: globalKey, initialUrl: 'about:blank', javascriptMode: JavascriptMode.unrestricted, userAgent: 'Custom_User_Agent1', @@ -204,7 +212,7 @@ Future main() async { Directionality( textDirection: TextDirection.ltr, child: WebView( - key: _globalKey, + key: globalKey, initialUrl: 'about:blank', javascriptMode: JavascriptMode.unrestricted, userAgent: 'Custom_User_Agent2', @@ -266,7 +274,6 @@ Future main() async { }); group('Programmatic Scroll', () { - // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757 testWidgets('setAndGetScrollPosition', (WidgetTester tester) async { const String scrollTestPage = ''' @@ -341,7 +348,7 @@ Future main() async { scrollPosY = await controller.getScrollY(); expect(scrollPosX, X_SCROLL * 2); expect(scrollPosY, Y_SCROLL * 2); - }, skip: Platform.isAndroid && _skipDueToIssue86757); + }); }); group('NavigationDelegate', () { @@ -514,7 +521,6 @@ Future main() async { }); }); - // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757 testWidgets( 'can open new window and go back', (WidgetTester tester) async { @@ -550,9 +556,8 @@ Future main() async { expect(controller.canGoBack(), completion(true)); await controller.goBack(); await pageLoaded.future; - expect(controller.currentUrl(), completion(primaryUrl)); + await expectLater(controller.currentUrl(), completion(primaryUrl)); }, - skip: _skipDueToIssue86757, ); } @@ -563,7 +568,7 @@ Future _getUserAgent(WebViewController controller) async { Future _runJavascriptReturningResult( WebViewController controller, String js) async { - return await controller.runJavascriptReturningResult(js); + return controller.runJavascriptReturningResult(js); } class ResizableWebView extends StatefulWidget { diff --git a/packages/webview_flutter/example/lib/main.dart b/packages/webview_flutter/example/lib/main.dart index a6298219c..ab0074c7f 100644 --- a/packages/webview_flutter/example/lib/main.dart +++ b/packages/webview_flutter/example/lib/main.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// ignore_for_file: public_member_api_docs +// ignore_for_file: public_member_api_docs, avoid_print import 'dart:async'; import 'dart:convert'; diff --git a/packages/webview_flutter_lwe/example/integration_test/webview_flutter_test.dart b/packages/webview_flutter_lwe/example/integration_test/webview_flutter_test.dart index 73827ce66..c3710f944 100644 --- a/packages/webview_flutter_lwe/example/integration_test/webview_flutter_test.dart +++ b/packages/webview_flutter_lwe/example/integration_test/webview_flutter_test.dart @@ -18,8 +18,6 @@ import 'package:webview_flutter/webview_flutter.dart'; Future main() async { IntegrationTestWidgetsFlutterBinding.ensureInitialized(); - const bool _skipDueToIssue86757 = true; - final HttpServer server = await HttpServer.bind(InternetAddress.anyIPv4, 0); server.forEach((HttpRequest request) { if (request.uri.path == '/hello.txt') { @@ -39,10 +37,10 @@ Future main() async { final String primaryUrl = '$prefixUrl/hello.txt'; final String secondaryUrl = '$prefixUrl/secondary.txt'; - // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757 testWidgets('initialUrl', (WidgetTester tester) async { final Completer controllerCompleter = Completer(); + final Completer pageFinishedCompleter = Completer(); await tester.pumpWidget( Directionality( textDirection: TextDirection.ltr, @@ -52,18 +50,22 @@ Future main() async { onWebViewCreated: (WebViewController controller) { controllerCompleter.complete(controller); }, + onPageFinished: pageFinishedCompleter.complete, ), ), ); + final WebViewController controller = await controllerCompleter.future; + await pageFinishedCompleter.future; + final String? currentUrl = await controller.currentUrl(); expect(currentUrl, primaryUrl); - }, skip: _skipDueToIssue86757); + }); - // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757 testWidgets('loadUrl', (WidgetTester tester) async { final Completer controllerCompleter = Completer(); + final StreamController pageLoads = StreamController(); await tester.pumpWidget( Directionality( textDirection: TextDirection.ltr, @@ -73,14 +75,20 @@ Future main() async { onWebViewCreated: (WebViewController controller) { controllerCompleter.complete(controller); }, + onPageFinished: (String url) { + pageLoads.add(url); + }, ), ), ); final WebViewController controller = await controllerCompleter.future; + await controller.loadUrl(secondaryUrl); - final String? currentUrl = await controller.currentUrl(); - expect(currentUrl, secondaryUrl); - }, skip: _skipDueToIssue86757); + await expectLater( + pageLoads.stream.firstWhere((String url) => url == secondaryUrl), + completion(secondaryUrl), + ); + }); testWidgets('evaluateJavascript', (WidgetTester tester) async { final Completer controllerCompleter = @@ -104,13 +112,12 @@ Future main() async { expect(result, equals('2')); }); - // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757 testWidgets('JavascriptChannel', (WidgetTester tester) async { final Completer controllerCompleter = Completer(); final Completer pageStarted = Completer(); final Completer pageLoaded = Completer(); - final List messagesReceived = []; + final Completer channelCompleter = Completer(); await tester.pumpWidget( Directionality( textDirection: TextDirection.ltr, @@ -127,7 +134,7 @@ Future main() async { JavascriptChannel( name: 'Echo', onMessageReceived: (JavascriptMessage message) { - messagesReceived.add(message.message); + channelCompleter.complete(message.message); }, ), }, @@ -144,10 +151,11 @@ Future main() async { await pageStarted.future; await pageLoaded.future; - expect(messagesReceived, isEmpty); + expect(channelCompleter.isCompleted, isFalse); await controller.runJavascript('Echo.postMessage("hello");'); - expect(messagesReceived, equals(['hello'])); - }, skip: Platform.isAndroid && _skipDueToIssue86757); + + await expectLater(channelCompleter.future, completion('hello')); + }); testWidgets('resize webview', (WidgetTester tester) async { final Completer initialResizeCompleter = Completer(); @@ -181,12 +189,12 @@ Future main() async { testWidgets('set custom userAgent', (WidgetTester tester) async { final Completer controllerCompleter1 = Completer(); - final GlobalKey _globalKey = GlobalKey(); + final GlobalKey globalKey = GlobalKey(); await tester.pumpWidget( Directionality( textDirection: TextDirection.ltr, child: WebView( - key: _globalKey, + key: globalKey, initialUrl: 'about:blank', javascriptMode: JavascriptMode.unrestricted, userAgent: 'Custom_User_Agent1', @@ -204,7 +212,7 @@ Future main() async { Directionality( textDirection: TextDirection.ltr, child: WebView( - key: _globalKey, + key: globalKey, initialUrl: 'about:blank', javascriptMode: JavascriptMode.unrestricted, userAgent: 'Custom_User_Agent2', @@ -266,7 +274,6 @@ Future main() async { }); group('Programmatic Scroll', () { - // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757 testWidgets('setAndGetScrollPosition', (WidgetTester tester) async { const String scrollTestPage = ''' @@ -341,7 +348,7 @@ Future main() async { scrollPosY = await controller.getScrollY(); expect(scrollPosX, X_SCROLL * 2); expect(scrollPosY, Y_SCROLL * 2); - }, skip: Platform.isAndroid && _skipDueToIssue86757); + }); }); group('NavigationDelegate', () { @@ -514,7 +521,6 @@ Future main() async { }); }); - // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757 testWidgets( 'can open new window and go back', (WidgetTester tester) async { @@ -550,9 +556,8 @@ Future main() async { expect(controller.canGoBack(), completion(true)); await controller.goBack(); await pageLoaded.future; - expect(controller.currentUrl(), completion(primaryUrl)); + await expectLater(controller.currentUrl(), completion(primaryUrl)); }, - skip: _skipDueToIssue86757, ); } @@ -563,7 +568,7 @@ Future _getUserAgent(WebViewController controller) async { Future _runJavascriptReturningResult( WebViewController controller, String js) async { - return await controller.runJavascriptReturningResult(js); + return controller.runJavascriptReturningResult(js); } class ResizableWebView extends StatefulWidget { diff --git a/packages/webview_flutter_lwe/example/lib/main.dart b/packages/webview_flutter_lwe/example/lib/main.dart index a6298219c..ab0074c7f 100644 --- a/packages/webview_flutter_lwe/example/lib/main.dart +++ b/packages/webview_flutter_lwe/example/lib/main.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// ignore_for_file: public_member_api_docs +// ignore_for_file: public_member_api_docs, avoid_print import 'dart:async'; import 'dart:convert';