Closed alegos27 closed 1 year ago
Hey @alegos27, you are entering the 123456
and it's length is the same as Pinput's length, what happens is that when you call await tester.testTextInput.receiveAction(TextInputAction.done);
the keyboard is already closed by Pinput so the onSumbitted callback is never called.
This test case works fine.
testWidgets(
'Pinput should call the onSubmitted callback when pin input is submitted',
(WidgetTester tester) async {
final pinController = TextEditingController();
String? submittedValue;
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Pinput(
controller: pinController,
onSubmitted: (value) {
submittedValue = value;
},
length: 6,
),
),
),
);
const pinValue = '12345';
await tester.enterText(find.byType(Pinput), pinValue);
await tester.testTextInput.receiveAction(TextInputAction.done);
await tester.pumpAndSettle();
expect(pinController.text, equals(pinValue));
expect(submittedValue, equals(pinValue));
},
);
Note that if you need a callback which is fired when pin is fully entered you should use onCompleted
property
Describe the bug During test seems onSubmitted callback does't work
To Reproduce
This is the result of test:
The following TestFailure was thrown running a test: Expected: '123456' Actual:
Which: not an <Instance of 'String'>
Pinput version: 2.2.31
Result of:
flutter doctor --verbose