Unverified Commit 1c7a1c38 authored by Alexandre Ardhuin's avatar Alexandre Ardhuin Committed by GitHub

implicit-casts:false in flutter/lib/src/services (#45723)

parent f908e182
...@@ -178,7 +178,7 @@ abstract class CachingAssetBundle extends AssetBundle { ...@@ -178,7 +178,7 @@ abstract class CachingAssetBundle extends AssetBundle {
assert(key != null); assert(key != null);
assert(parser != null); assert(parser != null);
if (_structuredDataCache.containsKey(key)) if (_structuredDataCache.containsKey(key))
return _structuredDataCache[key]; return _structuredDataCache[key] as Future<T>;
Completer<T> completer; Completer<T> completer;
Future<T> result; Future<T> result;
loadString(key, cache: false).then<T>(parser).then<void>((T value) { loadString(key, cache: false).then<T>(parser).then<void>((T value) {
......
...@@ -56,6 +56,6 @@ class Clipboard { ...@@ -56,6 +56,6 @@ class Clipboard {
); );
if (result == null) if (result == null)
return null; return null;
return ClipboardData(text: result['text']); return ClipboardData(text: result['text'] as String);
} }
} }
...@@ -171,8 +171,8 @@ class LogicalKeyboardKey extends KeyboardKey { ...@@ -171,8 +171,8 @@ class LogicalKeyboardKey extends KeyboardKey {
if (other.runtimeType != runtimeType) { if (other.runtimeType != runtimeType) {
return false; return false;
} }
final LogicalKeyboardKey typedOther = other; return other is LogicalKeyboardKey
return keyId == typedOther.keyId; && other.keyId == keyId;
} }
/// Returns the [LogicalKeyboardKey] constant that matches the given ID, or /// Returns the [LogicalKeyboardKey] constant that matches the given ID, or
...@@ -2073,8 +2073,8 @@ class PhysicalKeyboardKey extends KeyboardKey { ...@@ -2073,8 +2073,8 @@ class PhysicalKeyboardKey extends KeyboardKey {
if (other.runtimeType != runtimeType) { if (other.runtimeType != runtimeType) {
return false; return false;
} }
final PhysicalKeyboardKey typedOther = other; return other is PhysicalKeyboardKey
return usbHidUsage == typedOther.usbHidUsage; && other.usbHidUsage == usbHidUsage;
} }
@override @override
......
...@@ -147,8 +147,8 @@ class JSONMethodCodec implements MethodCodec { ...@@ -147,8 +147,8 @@ class JSONMethodCodec implements MethodCodec {
&& decoded[0] is String && decoded[0] is String
&& (decoded[1] == null || decoded[1] is String)) && (decoded[1] == null || decoded[1] is String))
throw PlatformException( throw PlatformException(
code: decoded[0], code: decoded[0] as String,
message: decoded[1], message: decoded[1] as String,
details: decoded[2], details: decoded[2],
); );
throw FormatException('Invalid envelope: $decoded'); throw FormatException('Invalid envelope: $decoded');
...@@ -356,7 +356,7 @@ class StandardMessageCodec implements MessageCodec<dynamic> { ...@@ -356,7 +356,7 @@ class StandardMessageCodec implements MessageCodec<dynamic> {
} }
} else if (value is String) { } else if (value is String) {
buffer.putUint8(_valueString); buffer.putUint8(_valueString);
final List<int> bytes = utf8.encoder.convert(value); final Uint8List bytes = utf8.encoder.convert(value);
writeSize(buffer, bytes.length); writeSize(buffer, bytes.length);
buffer.putUint8List(bytes); buffer.putUint8List(bytes);
} else if (value is Uint8List) { } else if (value is Uint8List) {
...@@ -566,7 +566,7 @@ class StandardMethodCodec implements MethodCodec { ...@@ -566,7 +566,7 @@ class StandardMethodCodec implements MethodCodec {
final dynamic errorMessage = messageCodec.readValue(buffer); final dynamic errorMessage = messageCodec.readValue(buffer);
final dynamic errorDetails = messageCodec.readValue(buffer); final dynamic errorDetails = messageCodec.readValue(buffer);
if (errorCode is String && (errorMessage == null || errorMessage is String) && !buffer.hasRemaining) if (errorCode is String && (errorMessage == null || errorMessage is String) && !buffer.hasRemaining)
throw PlatformException(code: errorCode, message: errorMessage, details: errorDetails); throw PlatformException(code: errorCode, message: errorMessage as String, details: errorDetails);
else else
throw const FormatException('Invalid envelope'); throw const FormatException('Invalid envelope');
} }
......
...@@ -318,7 +318,7 @@ class MethodChannel { ...@@ -318,7 +318,7 @@ class MethodChannel {
if (result == null) { if (result == null) {
throw MissingPluginException('No implementation found for method $method on channel $name'); throw MissingPluginException('No implementation found for method $method on channel $name');
} }
final T typedResult = codec.decodeEnvelope(result); final T typedResult = codec.decodeEnvelope(result) as T;
return typedResult; return typedResult;
} }
......
...@@ -65,7 +65,7 @@ class PlatformViewsService { ...@@ -65,7 +65,7 @@ class PlatformViewsService {
Future<void> _onMethodCall(MethodCall call) { Future<void> _onMethodCall(MethodCall call) {
switch(call.method) { switch(call.method) {
case 'viewFocused': case 'viewFocused':
final int id = call.arguments; final int id = call.arguments as int;
if (_focusCallbacks.containsKey(id)) { if (_focusCallbacks.containsKey(id)) {
_focusCallbacks[id](); _focusCallbacks[id]();
} }
......
...@@ -249,51 +249,51 @@ abstract class RawKeyEvent extends Diagnosticable { ...@@ -249,51 +249,51 @@ abstract class RawKeyEvent extends Diagnosticable {
factory RawKeyEvent.fromMessage(Map<String, dynamic> message) { factory RawKeyEvent.fromMessage(Map<String, dynamic> message) {
RawKeyEventData data; RawKeyEventData data;
final String keymap = message['keymap']; final String keymap = message['keymap'] as String;
switch (keymap) { switch (keymap) {
case 'android': case 'android':
data = RawKeyEventDataAndroid( data = RawKeyEventDataAndroid(
flags: message['flags'] ?? 0, flags: message['flags'] as int ?? 0,
codePoint: message['codePoint'] ?? 0, codePoint: message['codePoint'] as int ?? 0,
keyCode: message['keyCode'] ?? 0, keyCode: message['keyCode'] as int ?? 0,
plainCodePoint: message['plainCodePoint'] ?? 0, plainCodePoint: message['plainCodePoint'] as int ?? 0,
scanCode: message['scanCode'] ?? 0, scanCode: message['scanCode'] as int ?? 0,
metaState: message['metaState'] ?? 0, metaState: message['metaState'] as int ?? 0,
eventSource: message['source'] ?? 0, eventSource: message['source'] as int ?? 0,
vendorId: message['vendorId'] ?? 0, vendorId: message['vendorId'] as int ?? 0,
productId: message['productId'] ?? 0, productId: message['productId'] as int ?? 0,
deviceId: message['deviceId'] ?? 0, deviceId: message['deviceId'] as int ?? 0,
repeatCount: message['repeatCount'] ?? 0, repeatCount: message['repeatCount'] as int ?? 0,
); );
break; break;
case 'fuchsia': case 'fuchsia':
data = RawKeyEventDataFuchsia( data = RawKeyEventDataFuchsia(
hidUsage: message['hidUsage'] ?? 0, hidUsage: message['hidUsage'] as int ?? 0,
codePoint: message['codePoint'] ?? 0, codePoint: message['codePoint'] as int ?? 0,
modifiers: message['modifiers'] ?? 0, modifiers: message['modifiers'] as int ?? 0,
); );
break; break;
case 'macos': case 'macos':
data = RawKeyEventDataMacOs( data = RawKeyEventDataMacOs(
characters: message['characters'] ?? '', characters: message['characters'] as String ?? '',
charactersIgnoringModifiers: message['charactersIgnoringModifiers'] ?? '', charactersIgnoringModifiers: message['charactersIgnoringModifiers'] as String ?? '',
keyCode: message['keyCode'] ?? 0, keyCode: message['keyCode'] as int ?? 0,
modifiers: message['modifiers'] ?? 0); modifiers: message['modifiers'] as int ?? 0);
break; break;
case 'linux': case 'linux':
data = RawKeyEventDataLinux( data = RawKeyEventDataLinux(
keyHelper: KeyHelper(message['toolkit'] ?? ''), keyHelper: KeyHelper(message['toolkit'] as String ?? ''),
unicodeScalarValues: message['unicodeScalarValues'] ?? 0, unicodeScalarValues: message['unicodeScalarValues'] as int ?? 0,
keyCode: message['keyCode'] ?? 0, keyCode: message['keyCode'] as int ?? 0,
scanCode: message['scanCode'] ?? 0, scanCode: message['scanCode'] as int ?? 0,
modifiers: message['modifiers'] ?? 0, modifiers: message['modifiers'] as int ?? 0,
isDown: message['type'] == 'keydown'); isDown: message['type'] == 'keydown');
break; break;
case 'web': case 'web':
data = RawKeyEventDataWeb( data = RawKeyEventDataWeb(
code: message['code'], code: message['code'] as String,
key: message['key'], key: message['key'] as String,
metaState: message['metaState'], metaState: message['metaState'] as int,
); );
break; break;
default: default:
...@@ -303,10 +303,10 @@ abstract class RawKeyEvent extends Diagnosticable { ...@@ -303,10 +303,10 @@ abstract class RawKeyEvent extends Diagnosticable {
throw FlutterError('Unknown keymap for key events: $keymap'); throw FlutterError('Unknown keymap for key events: $keymap');
} }
final String type = message['type']; final String type = message['type'] as String;
switch (type) { switch (type) {
case 'keydown': case 'keydown':
return RawKeyDownEvent(data: data, character: message['character']); return RawKeyDownEvent(data: data, character: message['character'] as String);
case 'keyup': case 'keyup':
return RawKeyUpEvent(data: data); return RawKeyUpEvent(data: data);
default: default:
...@@ -498,7 +498,7 @@ class RawKeyboard { ...@@ -498,7 +498,7 @@ class RawKeyboard {
} }
Future<dynamic> _handleKeyEvent(dynamic message) async { Future<dynamic> _handleKeyEvent(dynamic message) async {
final RawKeyEvent event = RawKeyEvent.fromMessage(message); final RawKeyEvent event = RawKeyEvent.fromMessage(message as Map<String, dynamic>);
if (event == null) { if (event == null) {
return; return;
} }
......
...@@ -196,13 +196,13 @@ class SystemUiOverlayStyle { ...@@ -196,13 +196,13 @@ class SystemUiOverlayStyle {
bool operator ==(dynamic other) { bool operator ==(dynamic other) {
if (other.runtimeType != runtimeType) if (other.runtimeType != runtimeType)
return false; return false;
final SystemUiOverlayStyle typedOther = other; return other is SystemUiOverlayStyle
return typedOther.systemNavigationBarColor == systemNavigationBarColor && other.systemNavigationBarColor == systemNavigationBarColor
&& typedOther.systemNavigationBarDividerColor == systemNavigationBarDividerColor && other.systemNavigationBarDividerColor == systemNavigationBarDividerColor
&& typedOther.statusBarColor == statusBarColor && other.statusBarColor == statusBarColor
&& typedOther.statusBarIconBrightness == statusBarIconBrightness && other.statusBarIconBrightness == statusBarIconBrightness
&& typedOther.statusBarBrightness == statusBarBrightness && other.statusBarBrightness == statusBarBrightness
&& typedOther.systemNavigationBarIconBrightness == systemNavigationBarIconBrightness; && other.systemNavigationBarIconBrightness == systemNavigationBarIconBrightness;
} }
} }
......
...@@ -101,13 +101,11 @@ class TextSelection extends TextRange { ...@@ -101,13 +101,11 @@ class TextSelection extends TextRange {
bool operator ==(dynamic other) { bool operator ==(dynamic other) {
if (identical(this, other)) if (identical(this, other))
return true; return true;
if (other is! TextSelection) return other is TextSelection
return false; && other.baseOffset == baseOffset
final TextSelection typedOther = other; && other.extentOffset == extentOffset
return typedOther.baseOffset == baseOffset && other.affinity == affinity
&& typedOther.extentOffset == extentOffset && other.isDirectional == isDirectional;
&& typedOther.affinity == affinity
&& typedOther.isDirectional == isDirectional;
} }
@override @override
......
...@@ -142,12 +142,10 @@ class TextInputType { ...@@ -142,12 +142,10 @@ class TextInputType {
@override @override
bool operator ==(dynamic other) { bool operator ==(dynamic other) {
if (other is! TextInputType) return other is TextInputType
return false; && other.index == index
final TextInputType typedOther = other; && other.signed == signed
return typedOther.index == index && other.decimal == decimal;
&& typedOther.signed == signed
&& typedOther.decimal == decimal;
} }
@override @override
...@@ -529,16 +527,16 @@ class TextEditingValue { ...@@ -529,16 +527,16 @@ class TextEditingValue {
/// Creates an instance of this class from a JSON object. /// Creates an instance of this class from a JSON object.
factory TextEditingValue.fromJSON(Map<String, dynamic> encoded) { factory TextEditingValue.fromJSON(Map<String, dynamic> encoded) {
return TextEditingValue( return TextEditingValue(
text: encoded['text'], text: encoded['text'] as String,
selection: TextSelection( selection: TextSelection(
baseOffset: encoded['selectionBase'] ?? -1, baseOffset: encoded['selectionBase'] as int ?? -1,
extentOffset: encoded['selectionExtent'] ?? -1, extentOffset: encoded['selectionExtent'] as int ?? -1,
affinity: _toTextAffinity(encoded['selectionAffinity']) ?? TextAffinity.downstream, affinity: _toTextAffinity(encoded['selectionAffinity'] as String) ?? TextAffinity.downstream,
isDirectional: encoded['selectionIsDirectional'] ?? false, isDirectional: encoded['selectionIsDirectional'] as bool ?? false,
), ),
composing: TextRange( composing: TextRange(
start: encoded['composingBase'] ?? -1, start: encoded['composingBase'] as int ?? -1,
end: encoded['composingExtent'] ?? -1, end: encoded['composingExtent'] as int ?? -1,
), ),
); );
} }
...@@ -588,12 +586,10 @@ class TextEditingValue { ...@@ -588,12 +586,10 @@ class TextEditingValue {
bool operator ==(dynamic other) { bool operator ==(dynamic other) {
if (identical(this, other)) if (identical(this, other))
return true; return true;
if (other is! TextEditingValue) return other is TextEditingValue
return false; && other.text == text
final TextEditingValue typedOther = other; && other.selection == selection
return typedOther.text == text && other.composing == composing;
&& typedOther.selection == selection
&& typedOther.composing == composing;
} }
@override @override
...@@ -820,7 +816,9 @@ RawFloatingCursorPoint _toTextPoint(FloatingCursorDragState state, Map<String, d ...@@ -820,7 +816,9 @@ RawFloatingCursorPoint _toTextPoint(FloatingCursorDragState state, Map<String, d
assert(state != null, 'You must provide a state to set a new editing point.'); assert(state != null, 'You must provide a state to set a new editing point.');
assert(encoded['X'] != null, 'You must provide a value for the horizontal location of the floating cursor.'); assert(encoded['X'] != null, 'You must provide a value for the horizontal location of the floating cursor.');
assert(encoded['Y'] != null, 'You must provide a value for the vertical location of the floating cursor.'); assert(encoded['Y'] != null, 'You must provide a value for the vertical location of the floating cursor.');
final Offset offset = state == FloatingCursorDragState.Update ? Offset(encoded['X'], encoded['Y']) : const Offset(0, 0); final Offset offset = state == FloatingCursorDragState.Update
? Offset(encoded['X'] as double, encoded['Y'] as double)
: const Offset(0, 0);
return RawFloatingCursorPoint(offset: offset, state: state); return RawFloatingCursorPoint(offset: offset, state: state);
} }
...@@ -952,20 +950,23 @@ class TextInput { ...@@ -952,20 +950,23 @@ class TextInput {
return; return;
} }
final List<dynamic> args = methodCall.arguments; final List<dynamic> args = methodCall.arguments as List<dynamic>;
final int client = args[0]; final int client = args[0] as int;
// The incoming message was for a different client. // The incoming message was for a different client.
if (client != _currentConnection._id) if (client != _currentConnection._id)
return; return;
switch (method) { switch (method) {
case 'TextInputClient.updateEditingState': case 'TextInputClient.updateEditingState':
_currentConnection._client.updateEditingValue(TextEditingValue.fromJSON(args[1])); _currentConnection._client.updateEditingValue(TextEditingValue.fromJSON(args[1] as Map<String, dynamic>));
break; break;
case 'TextInputClient.performAction': case 'TextInputClient.performAction':
_currentConnection._client.performAction(_toTextInputAction(args[1])); _currentConnection._client.performAction(_toTextInputAction(args[1] as String));
break; break;
case 'TextInputClient.updateFloatingCursor': case 'TextInputClient.updateFloatingCursor':
_currentConnection._client.updateFloatingCursor(_toTextPoint(_toTextCursorAction(args[1]), args[2])); _currentConnection._client.updateFloatingCursor(_toTextPoint(
_toTextCursorAction(args[1] as String),
args[2] as Map<String, dynamic>,
));
break; break;
case 'TextInputClient.onConnectionClosed': case 'TextInputClient.onConnectionClosed':
_currentConnection._client.connectionClosed(); _currentConnection._client.connectionClosed();
......
...@@ -69,7 +69,7 @@ void main() { ...@@ -69,7 +69,7 @@ void main() {
} }
}, },
); );
expect(channel.invokeMethod<List<String>>('sayHello', 'hello'), throwsA(isInstanceOf<TypeError>())); expect(channel.invokeMethod<List<String>>('sayHello', 'hello'), throwsA(isInstanceOf<CastError>()));
expect(await channel.invokeListMethod<String>('sayHello', 'hello'), <String>['hello', 'world']); expect(await channel.invokeListMethod<String>('sayHello', 'hello'), <String>['hello', 'world']);
}); });
...@@ -101,7 +101,7 @@ void main() { ...@@ -101,7 +101,7 @@ void main() {
} }
}, },
); );
expect(channel.invokeMethod<Map<String, String>>('sayHello', 'hello'), throwsA(isInstanceOf<TypeError>())); expect(channel.invokeMethod<Map<String, String>>('sayHello', 'hello'), throwsA(isInstanceOf<CastError>()));
expect(await channel.invokeMapMethod<String, String>('sayHello', 'hello'), <String, String>{'hello': 'world'}); expect(await channel.invokeMapMethod<String, String>('sayHello', 'hello'), <String, String>{'hello': 'world'});
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment