Commit f06ef528 authored by Chris Bracken's avatar Chris Bracken Committed by GitHub

Verify EditableText fires update on replaced controller (#12276)

Adds a test that verifies that EditableText sends a
TextInput.setEditingState message to the engine when the associated
TextEditingController is replaced.
parent ad41de00
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter/services.dart';
......@@ -153,4 +154,61 @@ void main() {
expect(tester.testTextInput.setClientArgs['inputType'], equals('TextInputType.text'));
expect(tester.testTextInput.setClientArgs['inputAction'], equals('TextInputAction.done'));
});
testWidgets('Changing controller updates EditableText', (WidgetTester tester) async {
final GlobalKey<EditableTextState> editableTextKey = new GlobalKey<EditableTextState>();
final TextEditingController controller1 = new TextEditingController(text: 'Wibble');
final TextEditingController controller2 = new TextEditingController(text: 'Wobble');
TextEditingController currentController = controller1;
StateSetter setState;
Widget builder() {
return new StatefulBuilder(
builder: (BuildContext context, StateSetter setter) {
setState = setter;
return new Directionality(
textDirection: TextDirection.ltr,
child: new Center(
child: new Material(
child: new EditableText(
key: editableTextKey,
controller: currentController,
focusNode: new FocusNode(),
style: new Typography(platform: TargetPlatform.android).black.subhead,
cursorColor: Colors.blue,
selectionControls: materialTextSelectionControls,
keyboardType: TextInputType.text,
onChanged: (String value) { },
),
),
),
);
},
);
}
await tester.pumpWidget(builder());
await tester.showKeyboard(find.byType(EditableText));
// Verify TextInput.setEditingState is fired with updated text when controller is replaced.
final List<MethodCall> log = <MethodCall>[];
SystemChannels.textInput.setMockMethodCallHandler((MethodCall methodCall) {
log.add(methodCall);
});
setState(() {
currentController = controller2;
});
await tester.pump();
expect(log, <MethodCall>[
const MethodCall('TextInput.setEditingState', const <String, dynamic>{
'text': 'Wobble',
'selectionBase': -1,
'selectionExtent': -1,
'selectionAffinity': 'TextAffinity.downstream',
'selectionIsDirectional': false,
'composingBase': -1,
'composingExtent': -1,
}),
]);
});
}
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