Giter Site home page Giter Site logo

onSubmitted test fail about flutter_pinput HOT 1 CLOSED

alegos27 avatar alegos27 commented on May 20, 2024
onSubmitted test fail

from flutter_pinput.

Comments (1)

Tkko avatar Tkko commented on May 20, 2024

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

from flutter_pinput.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.