adar2378 / pin_code_fields

A flutter package which will help you to generate pin code fields with beautiful design and animations. Can be useful for OTP or pin code inputs 🤓🤓
https://pub.dev/packages/pin_code_fields
MIT License
690 stars 336 forks source link

Unable to enter values in PinCodeTextField within widget test #331

Closed KennethMurugu closed 1 year ago

KennethMurugu commented 1 year ago

I am attempting to find the PinCodeTextField by key and then setting its text value.

PinCodeTextField in my screen

PinCodeTextField(
                  key: Key('otp-field'),
                  animationType: AnimationType.scale,
                  keyboardType: TextInputType.number,
                  appContext: context,
                  autoFocus: true,
                  validator: (value) {
                    if (value!.length < 6) {
                      return 'Please enter a valid OTP';
                    }
                    return null;
                  },
                  errorTextSpace: 20,
                  pinTheme: PinTheme(
                    shape: PinCodeFieldShape.box,
                    borderRadius: BorderRadius.circular(8),
                    fieldHeight: 50,
                    fieldWidth: 40,
                    errorBorderColor: Theme.of(context).colorScheme.error,
                    activeFillColor: Theme.of(context).colorScheme.secondary,
                    selectedFillColor: Theme.of(context).colorScheme.primary,
                    selectedColor: Theme.of(context).colorScheme.primary,
                    activeColor: Theme.of(context).colorScheme.secondary,
                    inactiveColor: Theme.of(context).dividerColor,
                  ),
                  length: 6,
                  onCompleted: (value) {
                     //onCompleted
                   },
                  onChanged: (value) {

                  },
                ),

Widget test code

// ...
Finder findExpect(String key, {bool many = false}) {
  var finder = find.byKey(ValueKey(key));
  expect(finder, many ? findsWidgets : findsOneWidget);
  return finder;
}
// ...
var fieldOtp = findExpect('otp-field');

await tester.tap(fieldOtp);
await tester.pumpAndSettle();
await tester.enterText(fieldOtp, '000111');
await tester.pumpAndSettle();
stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.