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 {
assert(key != null);
assert(parser != null);
if (_structuredDataCache.containsKey(key))
return _structuredDataCache[key];
return _structuredDataCache[key] as Future<T>;
Completer<T> completer;
Future<T> result;
loadString(key, cache: false).then<T>(parser).then<void>((T value) {
......
......@@ -56,6 +56,6 @@ class Clipboard {
);
if (result == null)
return null;
return ClipboardData(text: result['text']);
return ClipboardData(text: result['text'] as String);
}
}
......@@ -171,8 +171,8 @@ class LogicalKeyboardKey extends KeyboardKey {
if (other.runtimeType != runtimeType) {
return false;
}
final LogicalKeyboardKey typedOther = other;
return keyId == typedOther.keyId;
return other is LogicalKeyboardKey
&& other.keyId == keyId;
}
/// Returns the [LogicalKeyboardKey] constant that matches the given ID, or
......@@ -2073,8 +2073,8 @@ class PhysicalKeyboardKey extends KeyboardKey {
if (other.runtimeType != runtimeType) {
return false;
}
final PhysicalKeyboardKey typedOther = other;
return usbHidUsage == typedOther.usbHidUsage;
return other is PhysicalKeyboardKey
&& other.usbHidUsage == usbHidUsage;
}
@override
......
......@@ -147,8 +147,8 @@ class JSONMethodCodec implements MethodCodec {
&& decoded[0] is String
&& (decoded[1] == null || decoded[1] is String))
throw PlatformException(
code: decoded[0],
message: decoded[1],
code: decoded[0] as String,
message: decoded[1] as String,
details: decoded[2],
);
throw FormatException('Invalid envelope: $decoded');
......@@ -356,7 +356,7 @@ class StandardMessageCodec implements MessageCodec<dynamic> {
}
} else if (value is String) {
buffer.putUint8(_valueString);
final List<int> bytes = utf8.encoder.convert(value);
final Uint8List bytes = utf8.encoder.convert(value);
writeSize(buffer, bytes.length);
buffer.putUint8List(bytes);
} else if (value is Uint8List) {
......@@ -566,7 +566,7 @@ class StandardMethodCodec implements MethodCodec {
final dynamic errorMessage = messageCodec.readValue(buffer);
final dynamic errorDetails = messageCodec.readValue(buffer);
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
throw const FormatException('Invalid envelope');
}
......
......@@ -318,7 +318,7 @@ class MethodChannel {
if (result == null) {
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;
}
......
......@@ -65,7 +65,7 @@ class PlatformViewsService {
Future<void> _onMethodCall(MethodCall call) {
switch(call.method) {
case 'viewFocused':
final int id = call.arguments;
final int id = call.arguments as int;
if (_focusCallbacks.containsKey(id)) {
_focusCallbacks[id]();
}
......
......@@ -249,51 +249,51 @@ abstract class RawKeyEvent extends Diagnosticable {
factory RawKeyEvent.fromMessage(Map<String, dynamic> message) {
RawKeyEventData data;
final String keymap = message['keymap'];
final String keymap = message['keymap'] as String;
switch (keymap) {
case 'android':
data = RawKeyEventDataAndroid(
flags: message['flags'] ?? 0,
codePoint: message['codePoint'] ?? 0,
keyCode: message['keyCode'] ?? 0,
plainCodePoint: message['plainCodePoint'] ?? 0,
scanCode: message['scanCode'] ?? 0,
metaState: message['metaState'] ?? 0,
eventSource: message['source'] ?? 0,
vendorId: message['vendorId'] ?? 0,
productId: message['productId'] ?? 0,
deviceId: message['deviceId'] ?? 0,
repeatCount: message['repeatCount'] ?? 0,
flags: message['flags'] as int ?? 0,
codePoint: message['codePoint'] as int ?? 0,
keyCode: message['keyCode'] as int ?? 0,
plainCodePoint: message['plainCodePoint'] as int ?? 0,
scanCode: message['scanCode'] as int ?? 0,
metaState: message['metaState'] as int ?? 0,
eventSource: message['source'] as int ?? 0,
vendorId: message['vendorId'] as int ?? 0,
productId: message['productId'] as int ?? 0,
deviceId: message['deviceId'] as int ?? 0,
repeatCount: message['repeatCount'] as int ?? 0,
);
break;
case 'fuchsia':
data = RawKeyEventDataFuchsia(
hidUsage: message['hidUsage'] ?? 0,
codePoint: message['codePoint'] ?? 0,
modifiers: message['modifiers'] ?? 0,
hidUsage: message['hidUsage'] as int ?? 0,
codePoint: message['codePoint'] as int ?? 0,
modifiers: message['modifiers'] as int ?? 0,
);
break;
case 'macos':
data = RawKeyEventDataMacOs(
characters: message['characters'] ?? '',
charactersIgnoringModifiers: message['charactersIgnoringModifiers'] ?? '',
keyCode: message['keyCode'] ?? 0,
modifiers: message['modifiers'] ?? 0);
characters: message['characters'] as String ?? '',
charactersIgnoringModifiers: message['charactersIgnoringModifiers'] as String ?? '',
keyCode: message['keyCode'] as int ?? 0,
modifiers: message['modifiers'] as int ?? 0);
break;
case 'linux':
data = RawKeyEventDataLinux(
keyHelper: KeyHelper(message['toolkit'] ?? ''),
unicodeScalarValues: message['unicodeScalarValues'] ?? 0,
keyCode: message['keyCode'] ?? 0,
scanCode: message['scanCode'] ?? 0,
modifiers: message['modifiers'] ?? 0,
keyHelper: KeyHelper(message['toolkit'] as String ?? ''),
unicodeScalarValues: message['unicodeScalarValues'] as int ?? 0,
keyCode: message['keyCode'] as int ?? 0,
scanCode: message['scanCode'] as int ?? 0,
modifiers: message['modifiers'] as int ?? 0,
isDown: message['type'] == 'keydown');
break;
case 'web':
data = RawKeyEventDataWeb(
code: message['code'],
key: message['key'],
metaState: message['metaState'],
code: message['code'] as String,
key: message['key'] as String,
metaState: message['metaState'] as int,
);
break;
default:
......@@ -303,10 +303,10 @@ abstract class RawKeyEvent extends Diagnosticable {
throw FlutterError('Unknown keymap for key events: $keymap');
}
final String type = message['type'];
final String type = message['type'] as String;
switch (type) {
case 'keydown':
return RawKeyDownEvent(data: data, character: message['character']);
return RawKeyDownEvent(data: data, character: message['character'] as String);
case 'keyup':
return RawKeyUpEvent(data: data);
default:
......@@ -498,7 +498,7 @@ class RawKeyboard {
}
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) {
return;
}
......
......@@ -196,13 +196,13 @@ class SystemUiOverlayStyle {
bool operator ==(dynamic other) {
if (other.runtimeType != runtimeType)
return false;
final SystemUiOverlayStyle typedOther = other;
return typedOther.systemNavigationBarColor == systemNavigationBarColor
&& typedOther.systemNavigationBarDividerColor == systemNavigationBarDividerColor
&& typedOther.statusBarColor == statusBarColor
&& typedOther.statusBarIconBrightness == statusBarIconBrightness
&& typedOther.statusBarBrightness == statusBarBrightness
&& typedOther.systemNavigationBarIconBrightness == systemNavigationBarIconBrightness;
return other is SystemUiOverlayStyle
&& other.systemNavigationBarColor == systemNavigationBarColor
&& other.systemNavigationBarDividerColor == systemNavigationBarDividerColor
&& other.statusBarColor == statusBarColor
&& other.statusBarIconBrightness == statusBarIconBrightness
&& other.statusBarBrightness == statusBarBrightness
&& other.systemNavigationBarIconBrightness == systemNavigationBarIconBrightness;
}
}
......
......@@ -101,13 +101,11 @@ class TextSelection extends TextRange {
bool operator ==(dynamic other) {
if (identical(this, other))
return true;
if (other is! TextSelection)
return false;
final TextSelection typedOther = other;
return typedOther.baseOffset == baseOffset
&& typedOther.extentOffset == extentOffset
&& typedOther.affinity == affinity
&& typedOther.isDirectional == isDirectional;
return other is TextSelection
&& other.baseOffset == baseOffset
&& other.extentOffset == extentOffset
&& other.affinity == affinity
&& other.isDirectional == isDirectional;
}
@override
......
......@@ -142,12 +142,10 @@ class TextInputType {
@override
bool operator ==(dynamic other) {
if (other is! TextInputType)
return false;
final TextInputType typedOther = other;
return typedOther.index == index
&& typedOther.signed == signed
&& typedOther.decimal == decimal;
return other is TextInputType
&& other.index == index
&& other.signed == signed
&& other.decimal == decimal;
}
@override
......@@ -529,16 +527,16 @@ class TextEditingValue {
/// Creates an instance of this class from a JSON object.
factory TextEditingValue.fromJSON(Map<String, dynamic> encoded) {
return TextEditingValue(
text: encoded['text'],
text: encoded['text'] as String,
selection: TextSelection(
baseOffset: encoded['selectionBase'] ?? -1,
extentOffset: encoded['selectionExtent'] ?? -1,
affinity: _toTextAffinity(encoded['selectionAffinity']) ?? TextAffinity.downstream,
isDirectional: encoded['selectionIsDirectional'] ?? false,
baseOffset: encoded['selectionBase'] as int ?? -1,
extentOffset: encoded['selectionExtent'] as int ?? -1,
affinity: _toTextAffinity(encoded['selectionAffinity'] as String) ?? TextAffinity.downstream,
isDirectional: encoded['selectionIsDirectional'] as bool ?? false,
),
composing: TextRange(
start: encoded['composingBase'] ?? -1,
end: encoded['composingExtent'] ?? -1,
start: encoded['composingBase'] as int ?? -1,
end: encoded['composingExtent'] as int ?? -1,
),
);
}
......@@ -588,12 +586,10 @@ class TextEditingValue {
bool operator ==(dynamic other) {
if (identical(this, other))
return true;
if (other is! TextEditingValue)
return false;
final TextEditingValue typedOther = other;
return typedOther.text == text
&& typedOther.selection == selection
&& typedOther.composing == composing;
return other is TextEditingValue
&& other.text == text
&& other.selection == selection
&& other.composing == composing;
}
@override
......@@ -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(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.');
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);
}
......@@ -952,20 +950,23 @@ class TextInput {
return;
}
final List<dynamic> args = methodCall.arguments;
final int client = args[0];
final List<dynamic> args = methodCall.arguments as List<dynamic>;
final int client = args[0] as int;
// The incoming message was for a different client.
if (client != _currentConnection._id)
return;
switch (method) {
case 'TextInputClient.updateEditingState':
_currentConnection._client.updateEditingValue(TextEditingValue.fromJSON(args[1]));
_currentConnection._client.updateEditingValue(TextEditingValue.fromJSON(args[1] as Map<String, dynamic>));
break;
case 'TextInputClient.performAction':
_currentConnection._client.performAction(_toTextInputAction(args[1]));
_currentConnection._client.performAction(_toTextInputAction(args[1] as String));
break;
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;
case 'TextInputClient.onConnectionClosed':
_currentConnection._client.connectionClosed();
......
......@@ -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']);
});
......@@ -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'});
});
......
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