Remove old platform messaging API (#8837)

Breaking change: removed deprecated methods of PlatformMessages, leaving only binary messaging there. All other use of platform communication now goes through PlatformMessageChannel and PlatformMethodChannels. Retained use of String and JSON codecs for now.

Companion engine PR: flutter/engine#3482
This commit is contained in:
Mikkel Nygaard Ravn
2017-03-17 11:56:50 +01:00
committed by GitHub
parent 3d3900871a
commit dce4bf8599
39 changed files with 578 additions and 555 deletions

View File

@@ -3,8 +3,6 @@
// found in the LICENSE file.
import 'dart:async';
import 'dart:convert';
import 'dart:typed_data';
import 'package:flutter/services.dart';
@@ -23,34 +21,35 @@ const String _kTextInputClientChannel = 'flutter/textinputclient';
/// popup keyboard and initializing its text.
class TestTextInput {
void register() {
PlatformMessages.setMockJSONMessageHandler('flutter/textinput', handleJSONMessage);
SystemChannels.textInput.setMockMethodCallHandler(handleTextInputCall);
}
int _client = 0;
Map<String, dynamic> editingState;
Future<dynamic> handleJSONMessage(dynamic message) async {
final String method = message['method'];
final List<dynamic> args= message['args'];
switch (method) {
Future<dynamic> handleTextInputCall(MethodCall methodCall) async {
switch (methodCall.method) {
case 'TextInput.setClient':
_client = args[0];
_client = methodCall.arguments[0];
break;
case 'TextInput.setEditingState':
editingState = args[0];
editingState = methodCall.arguments;
break;
}
}
void updateEditingState(TextEditingState state) {
expect(_client, isNonZero);
final String message = JSON.encode(<String, dynamic>{
'method': 'TextInputClient.updateEditingState',
'args': <dynamic>[_client, state.toJSON()],
});
final Uint8List encoded = UTF8.encoder.convert(message);
PlatformMessages.handlePlatformMessage(
_kTextInputClientChannel, encoded.buffer.asByteData(), (_) {});
SystemChannels.textInput.name,
SystemChannels.textInput.codec.encodeMethodCall(
new MethodCall(
'TextInputClient.updateEditingState',
<dynamic>[_client, state.toJSON()],
),
),
(_) {},
);
}
void enterText(String text) {