Skip to content

Commit 93535da

Browse files
stuartmorgan-gmauricioluz
authored andcommitted
[various] Enable avoid_dynamic_calls (flutter#6834)
* Enable the option * Fix camera * Fix webview * Remove unnecessary 'call's from camera tests * Fix maps * Fix sign-in * fix image_picker * Fix IAP * Fix shared_preferences * Fix url_launcher_android * Version bumps * Fix tool * Re-apply webview test fix * Re-bump versions * Fix one new tool issue
1 parent bb1cfe4 commit 93535da

File tree

69 files changed

+565
-330
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+565
-330
lines changed

analysis_options.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ linter:
6868
# - avoid_catching_errors # blocked on https://github.com/dart-lang/linter/issues/3023
6969
- avoid_classes_with_only_static_members
7070
- avoid_double_and_int_checks
71-
# - avoid_dynamic_calls # LOCAL CHANGE - Needs to be enabled and violations fixed.
71+
- avoid_dynamic_calls
7272
- avoid_empty_else
7373
- avoid_equals_and_hash_code_on_mutable_classes
7474
- avoid_escaping_inner_quotes

packages/camera/camera_android/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.10.2+1
2+
3+
* Updates code for stricter lint checks.
4+
15
## 0.10.2
26

37
* Remove usage of deprecated quiver Optional type.

packages/camera/camera_android/lib/src/android_camera.dart

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -549,9 +549,9 @@ class AndroidCamera extends CameraPlatform {
549549
Future<dynamic> _handleDeviceMethodCall(MethodCall call) async {
550550
switch (call.method) {
551551
case 'orientation_changed':
552+
final Map<String, Object?> arguments = _getArgumentDictionary(call);
552553
_deviceEventStreamController.add(DeviceOrientationChangedEvent(
553-
deserializeDeviceOrientation(
554-
call.arguments['orientation']! as String)));
554+
deserializeDeviceOrientation(arguments['orientation']! as String)));
555555
break;
556556
default:
557557
throw MissingPluginException();
@@ -566,21 +566,23 @@ class AndroidCamera extends CameraPlatform {
566566
Future<dynamic> handleCameraMethodCall(MethodCall call, int cameraId) async {
567567
switch (call.method) {
568568
case 'initialized':
569+
final Map<String, Object?> arguments = _getArgumentDictionary(call);
569570
cameraEventStreamController.add(CameraInitializedEvent(
570571
cameraId,
571-
call.arguments['previewWidth']! as double,
572-
call.arguments['previewHeight']! as double,
573-
deserializeExposureMode(call.arguments['exposureMode']! as String),
574-
call.arguments['exposurePointSupported']! as bool,
575-
deserializeFocusMode(call.arguments['focusMode']! as String),
576-
call.arguments['focusPointSupported']! as bool,
572+
arguments['previewWidth']! as double,
573+
arguments['previewHeight']! as double,
574+
deserializeExposureMode(arguments['exposureMode']! as String),
575+
arguments['exposurePointSupported']! as bool,
576+
deserializeFocusMode(arguments['focusMode']! as String),
577+
arguments['focusPointSupported']! as bool,
577578
));
578579
break;
579580
case 'resolution_changed':
581+
final Map<String, Object?> arguments = _getArgumentDictionary(call);
580582
cameraEventStreamController.add(CameraResolutionChangedEvent(
581583
cameraId,
582-
call.arguments['captureWidth']! as double,
583-
call.arguments['captureHeight']! as double,
584+
arguments['captureWidth']! as double,
585+
arguments['captureHeight']! as double,
584586
));
585587
break;
586588
case 'camera_closing':
@@ -589,23 +591,32 @@ class AndroidCamera extends CameraPlatform {
589591
));
590592
break;
591593
case 'video_recorded':
594+
final Map<String, Object?> arguments = _getArgumentDictionary(call);
592595
cameraEventStreamController.add(VideoRecordedEvent(
593596
cameraId,
594-
XFile(call.arguments['path']! as String),
595-
call.arguments['maxVideoDuration'] != null
596-
? Duration(
597-
milliseconds: call.arguments['maxVideoDuration']! as int)
597+
XFile(arguments['path']! as String),
598+
arguments['maxVideoDuration'] != null
599+
? Duration(milliseconds: arguments['maxVideoDuration']! as int)
598600
: null,
599601
));
600602
break;
601603
case 'error':
604+
final Map<String, Object?> arguments = _getArgumentDictionary(call);
602605
cameraEventStreamController.add(CameraErrorEvent(
603606
cameraId,
604-
call.arguments['description']! as String,
607+
arguments['description']! as String,
605608
));
606609
break;
607610
default:
608611
throw MissingPluginException();
609612
}
610613
}
614+
615+
/// Returns the arguments of [call] as typed string-keyed Map.
616+
///
617+
/// This does not do any type validation, so is only safe to call if the
618+
/// arguments are known to be a map.
619+
Map<String, Object?> _getArgumentDictionary(MethodCall call) {
620+
return (call.arguments as Map<Object?, Object?>).cast<String, Object?>();
621+
}
611622
}

packages/camera/camera_android/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: camera_android
22
description: Android implementation of the camera plugin.
33
repository: https://github.com/flutter/plugins/tree/main/packages/camera/camera_android
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
5-
version: 0.10.2
5+
version: 0.10.2+1
66

77
environment:
88
sdk: ">=2.14.0 <3.0.0"

packages/camera/camera_android/test/android_camera_test.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,11 +504,13 @@ void main() {
504504
]);
505505
expect(cameras.length, returnData.length);
506506
for (int i = 0; i < returnData.length; i++) {
507+
final Map<String, Object?> typedData =
508+
(returnData[i] as Map<dynamic, dynamic>).cast<String, Object?>();
507509
final CameraDescription cameraDescription = CameraDescription(
508-
name: returnData[i]['name']! as String,
510+
name: typedData['name']! as String,
509511
lensDirection:
510-
parseCameraLensDirection(returnData[i]['lensFacing']! as String),
511-
sensorOrientation: returnData[i]['sensorOrientation']! as int,
512+
parseCameraLensDirection(typedData['lensFacing']! as String),
513+
sensorOrientation: typedData['sensorOrientation']! as int,
512514
);
513515
expect(cameras[i], cameraDescription);
514516
}

packages/camera/camera_android_camerax/lib/src/instance_manager.dart

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,22 +124,26 @@ class InstanceManager {
124124
/// This method also expects the host `InstanceManager` to have a strong
125125
/// reference to the instance the identifier is associated with.
126126
T? getInstanceWithWeakReference<T extends Object>(int identifier) {
127-
final Object? weakInstance = _weakInstances[identifier]?.target;
127+
final T? weakInstance = _weakInstances[identifier]?.target as T?;
128128

129129
if (weakInstance == null) {
130-
final Object? strongInstance = _strongInstances[identifier];
130+
final T? strongInstance = _strongInstances[identifier] as T?;
131131
if (strongInstance != null) {
132-
final Object copy =
133-
_copyCallbacks[identifier]!(strongInstance)! as Object;
132+
// This cast is safe since it matches the argument type for
133+
// _addInstanceWithIdentifier, which is the only place _copyCallbacks
134+
// is populated.
135+
final T Function(T) copyCallback =
136+
_copyCallbacks[identifier]! as T Function(T);
137+
final T copy = copyCallback(strongInstance);
134138
_identifiers[copy] = identifier;
135-
_weakInstances[identifier] = WeakReference<Object>(copy);
139+
_weakInstances[identifier] = WeakReference<T>(copy);
136140
_finalizer.attach(copy, identifier, detach: copy);
137-
return copy as T;
141+
return copy;
138142
}
139-
return strongInstance as T?;
143+
return strongInstance;
140144
}
141145

142-
return weakInstance as T;
146+
return weakInstance;
143147
}
144148

145149
/// Retrieves the identifier associated with instance.

packages/camera/camera_avfoundation/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.9.10+1
2+
3+
* Updates code for stricter lint checks.
4+
15
## 0.9.10
26

37
* Remove usage of deprecated quiver Optional type.

packages/camera/camera_avfoundation/lib/src/avfoundation_camera.dart

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -555,9 +555,9 @@ class AVFoundationCamera extends CameraPlatform {
555555
Future<dynamic> _handleDeviceMethodCall(MethodCall call) async {
556556
switch (call.method) {
557557
case 'orientation_changed':
558+
final Map<String, Object?> arguments = _getArgumentDictionary(call);
558559
_deviceEventStreamController.add(DeviceOrientationChangedEvent(
559-
deserializeDeviceOrientation(
560-
call.arguments['orientation']! as String)));
560+
deserializeDeviceOrientation(arguments['orientation']! as String)));
561561
break;
562562
default:
563563
throw MissingPluginException();
@@ -572,21 +572,23 @@ class AVFoundationCamera extends CameraPlatform {
572572
Future<dynamic> handleCameraMethodCall(MethodCall call, int cameraId) async {
573573
switch (call.method) {
574574
case 'initialized':
575+
final Map<String, Object?> arguments = _getArgumentDictionary(call);
575576
cameraEventStreamController.add(CameraInitializedEvent(
576577
cameraId,
577-
call.arguments['previewWidth']! as double,
578-
call.arguments['previewHeight']! as double,
579-
deserializeExposureMode(call.arguments['exposureMode']! as String),
580-
call.arguments['exposurePointSupported']! as bool,
581-
deserializeFocusMode(call.arguments['focusMode']! as String),
582-
call.arguments['focusPointSupported']! as bool,
578+
arguments['previewWidth']! as double,
579+
arguments['previewHeight']! as double,
580+
deserializeExposureMode(arguments['exposureMode']! as String),
581+
arguments['exposurePointSupported']! as bool,
582+
deserializeFocusMode(arguments['focusMode']! as String),
583+
arguments['focusPointSupported']! as bool,
583584
));
584585
break;
585586
case 'resolution_changed':
587+
final Map<String, Object?> arguments = _getArgumentDictionary(call);
586588
cameraEventStreamController.add(CameraResolutionChangedEvent(
587589
cameraId,
588-
call.arguments['captureWidth']! as double,
589-
call.arguments['captureHeight']! as double,
590+
arguments['captureWidth']! as double,
591+
arguments['captureHeight']! as double,
590592
));
591593
break;
592594
case 'camera_closing':
@@ -595,23 +597,32 @@ class AVFoundationCamera extends CameraPlatform {
595597
));
596598
break;
597599
case 'video_recorded':
600+
final Map<String, Object?> arguments = _getArgumentDictionary(call);
598601
cameraEventStreamController.add(VideoRecordedEvent(
599602
cameraId,
600-
XFile(call.arguments['path']! as String),
601-
call.arguments['maxVideoDuration'] != null
602-
? Duration(
603-
milliseconds: call.arguments['maxVideoDuration']! as int)
603+
XFile(arguments['path']! as String),
604+
arguments['maxVideoDuration'] != null
605+
? Duration(milliseconds: arguments['maxVideoDuration']! as int)
604606
: null,
605607
));
606608
break;
607609
case 'error':
610+
final Map<String, Object?> arguments = _getArgumentDictionary(call);
608611
cameraEventStreamController.add(CameraErrorEvent(
609612
cameraId,
610-
call.arguments['description']! as String,
613+
arguments['description']! as String,
611614
));
612615
break;
613616
default:
614617
throw MissingPluginException();
615618
}
616619
}
620+
621+
/// Returns the arguments of [call] as typed string-keyed Map.
622+
///
623+
/// This does not do any type validation, so is only safe to call if the
624+
/// arguments are known to be a map.
625+
Map<String, Object?> _getArgumentDictionary(MethodCall call) {
626+
return (call.arguments as Map<Object?, Object?>).cast<String, Object?>();
627+
}
617628
}

packages/camera/camera_avfoundation/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: camera_avfoundation
22
description: iOS implementation of the camera plugin.
33
repository: https://github.com/flutter/plugins/tree/main/packages/camera/camera_avfoundation
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
5-
version: 0.9.10
5+
version: 0.9.10+1
66

77
environment:
88
sdk: ">=2.14.0 <3.0.0"

packages/camera/camera_avfoundation/test/avfoundation_camera_test.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,9 @@ void main() {
478478
test('Should fetch CameraDescription instances for available cameras',
479479
() async {
480480
// Arrange
481+
// This deliberately uses 'dynamic' since that's what actual platform
482+
// channel results will be, so using typed mock data could mask type
483+
// handling bugs in the code under test.
481484
final List<dynamic> returnData = <dynamic>[
482485
<String, dynamic>{
483486
'name': 'Test 1',
@@ -504,11 +507,13 @@ void main() {
504507
]);
505508
expect(cameras.length, returnData.length);
506509
for (int i = 0; i < returnData.length; i++) {
510+
final Map<String, Object?> typedData =
511+
(returnData[i] as Map<dynamic, dynamic>).cast<String, Object?>();
507512
final CameraDescription cameraDescription = CameraDescription(
508-
name: returnData[i]['name']! as String,
513+
name: typedData['name']! as String,
509514
lensDirection:
510-
parseCameraLensDirection(returnData[i]['lensFacing']! as String),
511-
sensorOrientation: returnData[i]['sensorOrientation']! as int,
515+
parseCameraLensDirection(typedData['lensFacing']! as String),
516+
sensorOrientation: typedData['sensorOrientation']! as int,
512517
);
513518
expect(cameras[i], cameraDescription);
514519
}

packages/camera/camera_platform_interface/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.3.3
2+
3+
* Updates code for stricter lint checks.
4+
15
## 2.3.2
26

37
* Updates MethodChannelCamera to have startVideoRecording call the newer startVideoCapturing.

packages/camera/camera_platform_interface/lib/src/method_channel/method_channel_camera.dart

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -551,9 +551,9 @@ class MethodChannelCamera extends CameraPlatform {
551551
Future<dynamic> handleDeviceMethodCall(MethodCall call) async {
552552
switch (call.method) {
553553
case 'orientation_changed':
554+
final Map<String, Object?> arguments = _getArgumentDictionary(call);
554555
deviceEventStreamController.add(DeviceOrientationChangedEvent(
555-
deserializeDeviceOrientation(
556-
call.arguments['orientation']! as String)));
556+
deserializeDeviceOrientation(arguments['orientation']! as String)));
557557
break;
558558
default:
559559
throw MissingPluginException();
@@ -568,21 +568,23 @@ class MethodChannelCamera extends CameraPlatform {
568568
Future<dynamic> handleCameraMethodCall(MethodCall call, int cameraId) async {
569569
switch (call.method) {
570570
case 'initialized':
571+
final Map<String, Object?> arguments = _getArgumentDictionary(call);
571572
cameraEventStreamController.add(CameraInitializedEvent(
572573
cameraId,
573-
call.arguments['previewWidth']! as double,
574-
call.arguments['previewHeight']! as double,
575-
deserializeExposureMode(call.arguments['exposureMode']! as String),
576-
call.arguments['exposurePointSupported']! as bool,
577-
deserializeFocusMode(call.arguments['focusMode']! as String),
578-
call.arguments['focusPointSupported']! as bool,
574+
arguments['previewWidth']! as double,
575+
arguments['previewHeight']! as double,
576+
deserializeExposureMode(arguments['exposureMode']! as String),
577+
arguments['exposurePointSupported']! as bool,
578+
deserializeFocusMode(arguments['focusMode']! as String),
579+
arguments['focusPointSupported']! as bool,
579580
));
580581
break;
581582
case 'resolution_changed':
583+
final Map<String, Object?> arguments = _getArgumentDictionary(call);
582584
cameraEventStreamController.add(CameraResolutionChangedEvent(
583585
cameraId,
584-
call.arguments['captureWidth']! as double,
585-
call.arguments['captureHeight']! as double,
586+
arguments['captureWidth']! as double,
587+
arguments['captureHeight']! as double,
586588
));
587589
break;
588590
case 'camera_closing':
@@ -591,23 +593,32 @@ class MethodChannelCamera extends CameraPlatform {
591593
));
592594
break;
593595
case 'video_recorded':
596+
final Map<String, Object?> arguments = _getArgumentDictionary(call);
594597
cameraEventStreamController.add(VideoRecordedEvent(
595598
cameraId,
596-
XFile(call.arguments['path']! as String),
597-
call.arguments['maxVideoDuration'] != null
598-
? Duration(
599-
milliseconds: call.arguments['maxVideoDuration']! as int)
599+
XFile(arguments['path']! as String),
600+
arguments['maxVideoDuration'] != null
601+
? Duration(milliseconds: arguments['maxVideoDuration']! as int)
600602
: null,
601603
));
602604
break;
603605
case 'error':
606+
final Map<String, Object?> arguments = _getArgumentDictionary(call);
604607
cameraEventStreamController.add(CameraErrorEvent(
605608
cameraId,
606-
call.arguments['description']! as String,
609+
arguments['description']! as String,
607610
));
608611
break;
609612
default:
610613
throw MissingPluginException();
611614
}
612615
}
616+
617+
/// Returns the arguments of [call] as typed string-keyed Map.
618+
///
619+
/// This does not do any type validation, so is only safe to call if the
620+
/// arguments are known to be a map.
621+
Map<String, Object?> _getArgumentDictionary(MethodCall call) {
622+
return (call.arguments as Map<Object?, Object?>).cast<String, Object?>();
623+
}
613624
}

packages/camera/camera_platform_interface/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repository: https://github.com/flutter/plugins/tree/main/packages/camera/camera_
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
55
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
66
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
7-
version: 2.3.2
7+
version: 2.3.3
88

99
environment:
1010
sdk: '>=2.12.0 <3.0.0'

0 commit comments

Comments
 (0)