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.
This commit is contained in:
parent
ad41de0059
commit
f06ef528e9
@ -3,6 +3,7 @@
|
|||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
@ -153,4 +154,61 @@ void main() {
|
|||||||
expect(tester.testTextInput.setClientArgs['inputType'], equals('TextInputType.text'));
|
expect(tester.testTextInput.setClientArgs['inputType'], equals('TextInputType.text'));
|
||||||
expect(tester.testTextInput.setClientArgs['inputAction'], equals('TextInputAction.done'));
|
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,
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user