@@ -458,31 +458,62 @@ void main() {
458
458
expect (fakeTextChannel.outgoingCalls, isEmpty);
459
459
});
460
460
461
- test ('receives visual input control requests' , () async {
461
+ test ('both input controls receive requests' , () async {
462
462
final FakeTextInputControl control = FakeTextInputControl ();
463
463
TextInput .setInputControl (control);
464
464
465
+ const TextInputConfiguration textConfig = TextInputConfiguration (inputType: TextInputType .text);
466
+ const TextInputConfiguration numberConfig = TextInputConfiguration (inputType: TextInputType .number);
467
+ const TextInputConfiguration noneConfig = TextInputConfiguration (inputType: TextInputType .none);
468
+
465
469
final FakeTextInputClient client = FakeTextInputClient (TextEditingValue .empty);
466
- final TextInputConnection connection = TextInput .attach (client, const TextInputConfiguration () );
470
+ final TextInputConnection connection = TextInput .attach (client, textConfig );
467
471
468
472
final List <String > expectedMethodCalls = < String > ['attach' ];
469
473
expect (control.methodCalls, expectedMethodCalls);
474
+ expect (control.inputType, TextInputType .text);
475
+ fakeTextChannel.validateOutgoingMethodCalls (< MethodCall > [
476
+ // When there's a custom text input control installed, the platform text
477
+ // input control receives TextInputType.none
478
+ MethodCall ('TextInput.setClient' , < dynamic > [1 , noneConfig.toJson ()]),
479
+ ]);
470
480
471
481
connection.show ();
472
482
expectedMethodCalls.add ('show' );
473
483
expect (control.methodCalls, expectedMethodCalls);
484
+ expect (fakeTextChannel.outgoingCalls.length, 2 );
485
+ expect (fakeTextChannel.outgoingCalls.last.method, 'TextInput.show' );
486
+
487
+ connection.updateConfig (numberConfig);
488
+ expectedMethodCalls.add ('updateConfig' );
489
+ expect (control.methodCalls, expectedMethodCalls);
490
+ expect (control.inputType, TextInputType .number);
491
+ expect (fakeTextChannel.outgoingCalls.length, 3 );
492
+ fakeTextChannel.validateOutgoingMethodCalls (< MethodCall > [
493
+ // When there's a custom text input control installed, the platform text
494
+ // input control receives TextInputType.none
495
+ MethodCall ('TextInput.setClient' , < dynamic > [1 , noneConfig.toJson ()]),
496
+ const MethodCall ('TextInput.show' ),
497
+ MethodCall ('TextInput.updateConfig' , noneConfig.toJson ()),
498
+ ]);
474
499
475
500
connection.setComposingRect (Rect .zero);
476
501
expectedMethodCalls.add ('setComposingRect' );
477
502
expect (control.methodCalls, expectedMethodCalls);
503
+ expect (fakeTextChannel.outgoingCalls.length, 4 );
504
+ expect (fakeTextChannel.outgoingCalls.last.method, 'TextInput.setMarkedTextRect' );
478
505
479
506
connection.setCaretRect (Rect .zero);
480
507
expectedMethodCalls.add ('setCaretRect' );
481
508
expect (control.methodCalls, expectedMethodCalls);
509
+ expect (fakeTextChannel.outgoingCalls.length, 5 );
510
+ expect (fakeTextChannel.outgoingCalls.last.method, 'TextInput.setCaretRect' );
482
511
483
512
connection.setEditableSizeAndTransform (Size .zero, Matrix4 .identity ());
484
513
expectedMethodCalls.add ('setEditableSizeAndTransform' );
485
514
expect (control.methodCalls, expectedMethodCalls);
515
+ expect (fakeTextChannel.outgoingCalls.length, 6 );
516
+ expect (fakeTextChannel.outgoingCalls.last.method, 'TextInput.setEditableSizeAndTransform' );
486
517
487
518
connection.setStyle (
488
519
fontFamily: null ,
@@ -493,15 +524,21 @@ void main() {
493
524
);
494
525
expectedMethodCalls.add ('setStyle' );
495
526
expect (control.methodCalls, expectedMethodCalls);
527
+ expect (fakeTextChannel.outgoingCalls.length, 7 );
528
+ expect (fakeTextChannel.outgoingCalls.last.method, 'TextInput.setStyle' );
496
529
497
530
connection.close ();
498
531
expectedMethodCalls.add ('detach' );
499
532
expect (control.methodCalls, expectedMethodCalls);
533
+ expect (fakeTextChannel.outgoingCalls.length, 8 );
534
+ expect (fakeTextChannel.outgoingCalls.last.method, 'TextInput.clearClient' );
500
535
501
536
expectedMethodCalls.add ('hide' );
502
537
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding .ensureInitialized () as TestWidgetsFlutterBinding ;
503
538
await binding.runAsync (() async {});
504
539
await expectLater (control.methodCalls, expectedMethodCalls);
540
+ expect (fakeTextChannel.outgoingCalls.length, 9 );
541
+ expect (fakeTextChannel.outgoingCalls.last.method, 'TextInput.hide' );
505
542
});
506
543
507
544
test ('notifies changes to the attached client' , () async {
@@ -628,10 +665,12 @@ class FakeTextChannel implements MethodChannel {
628
665
629
666
class FakeTextInputControl extends TextInputControl {
630
667
final List <String > methodCalls = < String > [];
668
+ late TextInputType inputType;
631
669
632
670
@override
633
671
void attach (TextInputClient client, TextInputConfiguration configuration) {
634
672
methodCalls.add ('attach' );
673
+ inputType = configuration.inputType;
635
674
}
636
675
637
676
@override
@@ -647,6 +686,7 @@ class FakeTextInputControl extends TextInputControl {
647
686
@override
648
687
void updateConfig (TextInputConfiguration configuration) {
649
688
methodCalls.add ('updateConfig' );
689
+ inputType = configuration.inputType;
650
690
}
651
691
652
692
@override
0 commit comments