diff --git a/packages/flutter/lib/src/services/asset_bundle.dart b/packages/flutter/lib/src/services/asset_bundle.dart index 5a5977e419..ca65bbe1f1 100644 --- a/packages/flutter/lib/src/services/asset_bundle.dart +++ b/packages/flutter/lib/src/services/asset_bundle.dart @@ -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; Completer completer; Future result; loadString(key, cache: false).then(parser).then((T value) { diff --git a/packages/flutter/lib/src/services/clipboard.dart b/packages/flutter/lib/src/services/clipboard.dart index 8263b134cf..cf720549be 100644 --- a/packages/flutter/lib/src/services/clipboard.dart +++ b/packages/flutter/lib/src/services/clipboard.dart @@ -56,6 +56,6 @@ class Clipboard { ); if (result == null) return null; - return ClipboardData(text: result['text']); + return ClipboardData(text: result['text'] as String); } } diff --git a/packages/flutter/lib/src/services/keyboard_key.dart b/packages/flutter/lib/src/services/keyboard_key.dart index 3dbc8c7d99..c9eb338f24 100644 --- a/packages/flutter/lib/src/services/keyboard_key.dart +++ b/packages/flutter/lib/src/services/keyboard_key.dart @@ -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 diff --git a/packages/flutter/lib/src/services/message_codecs.dart b/packages/flutter/lib/src/services/message_codecs.dart index 836fd0d475..2c13b1d283 100644 --- a/packages/flutter/lib/src/services/message_codecs.dart +++ b/packages/flutter/lib/src/services/message_codecs.dart @@ -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 { } } else if (value is String) { buffer.putUint8(_valueString); - final List 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'); } diff --git a/packages/flutter/lib/src/services/platform_channel.dart b/packages/flutter/lib/src/services/platform_channel.dart index 16ba244321..5fe5450d60 100644 --- a/packages/flutter/lib/src/services/platform_channel.dart +++ b/packages/flutter/lib/src/services/platform_channel.dart @@ -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; } diff --git a/packages/flutter/lib/src/services/platform_views.dart b/packages/flutter/lib/src/services/platform_views.dart index 2ca29ad502..a43cb274fd 100644 --- a/packages/flutter/lib/src/services/platform_views.dart +++ b/packages/flutter/lib/src/services/platform_views.dart @@ -65,7 +65,7 @@ class PlatformViewsService { Future _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](); } diff --git a/packages/flutter/lib/src/services/raw_keyboard.dart b/packages/flutter/lib/src/services/raw_keyboard.dart index 4a39251d18..6d3969d3c1 100644 --- a/packages/flutter/lib/src/services/raw_keyboard.dart +++ b/packages/flutter/lib/src/services/raw_keyboard.dart @@ -249,51 +249,51 @@ abstract class RawKeyEvent extends Diagnosticable { factory RawKeyEvent.fromMessage(Map 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 _handleKeyEvent(dynamic message) async { - final RawKeyEvent event = RawKeyEvent.fromMessage(message); + final RawKeyEvent event = RawKeyEvent.fromMessage(message as Map); if (event == null) { return; } diff --git a/packages/flutter/lib/src/services/system_chrome.dart b/packages/flutter/lib/src/services/system_chrome.dart index af6efab48b..39aa311d5e 100644 --- a/packages/flutter/lib/src/services/system_chrome.dart +++ b/packages/flutter/lib/src/services/system_chrome.dart @@ -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; } } diff --git a/packages/flutter/lib/src/services/text_editing.dart b/packages/flutter/lib/src/services/text_editing.dart index 75c4f51457..9b10271802 100644 --- a/packages/flutter/lib/src/services/text_editing.dart +++ b/packages/flutter/lib/src/services/text_editing.dart @@ -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 diff --git a/packages/flutter/lib/src/services/text_input.dart b/packages/flutter/lib/src/services/text_input.dart index a84991afe6..e9866d248b 100644 --- a/packages/flutter/lib/src/services/text_input.dart +++ b/packages/flutter/lib/src/services/text_input.dart @@ -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 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 args = methodCall.arguments; - final int client = args[0]; + final List args = methodCall.arguments as List; + 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)); 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, + )); break; case 'TextInputClient.onConnectionClosed': _currentConnection._client.connectionClosed(); diff --git a/packages/flutter/test/services/platform_channel_test.dart b/packages/flutter/test/services/platform_channel_test.dart index ed3cc05594..26d42a7f8b 100644 --- a/packages/flutter/test/services/platform_channel_test.dart +++ b/packages/flutter/test/services/platform_channel_test.dart @@ -69,7 +69,7 @@ void main() { } }, ); - expect(channel.invokeMethod>('sayHello', 'hello'), throwsA(isInstanceOf())); + expect(channel.invokeMethod>('sayHello', 'hello'), throwsA(isInstanceOf())); expect(await channel.invokeListMethod('sayHello', 'hello'), ['hello', 'world']); }); @@ -101,7 +101,7 @@ void main() { } }, ); - expect(channel.invokeMethod>('sayHello', 'hello'), throwsA(isInstanceOf())); + expect(channel.invokeMethod>('sayHello', 'hello'), throwsA(isInstanceOf())); expect(await channel.invokeMapMethod('sayHello', 'hello'), {'hello': 'world'}); });