Coder Social home page Coder Social logo

Comments (6)

TheDevelolper avatar TheDevelolper commented on July 20, 2024 2

@natintosh I see a similar error when I set autovalidate to true:

       InternationalPhoneNumberInput(
                    countries: ["GB"],
                    initialValue: initialPhoneNumber,
                    ignoreBlank: true,
                    autoValidate: true,
                    textFieldController: controller,
                    inputBorder: OutlineInputBorder(),
                    selectorType: PhoneInputSelectorType.BOTTOM_SHEET,
                  ),

I get an error saying setState() or markNeedsBuild called during build...

if I turn autovalidate off then I don't see the error?!

from intl_phone_number_input.

natintosh avatar natintosh commented on July 20, 2024 1

Hi @ISimplifyComplexity I published a fixed to this issue thanks for bringing this up

from intl_phone_number_input.

natintosh avatar natintosh commented on July 20, 2024

@b02505048 thanks for raising this issue. I have been unable to reproduce this issue and it seems to work fine at my end, but the cause of this is an external dependency that throws an exception when this is not true

if (!isViablePhoneNumber(nationalNumber)) {
      throw new NumberParseException(NumberParseException.ErrorType.NOT_A_NUMBER,
          "The string supplied did not seem to be a phone number.");
    }
  /**
   * Checks to see if the string of characters could possibly be a phone number at all. At the
   * moment, checks to see that the string begins with at least 2 digits, ignoring any punctuation
   * commonly found in phone numbers.
   * This method does not require the number to be normalized in advance - but does assume that
   * leading non-number symbols have been removed, such as by the method extractPossibleNumber.
   *
   * @param number  string to be checked for viability as a phone number
   * @return  true if the number could be a phone number of some sort, otherwise false
   */
  // @VisibleForTesting
  static boolean isViablePhoneNumber(CharSequence number) {
    if (number.length() < MIN_LENGTH_FOR_NSN) {
      return false;
    }
    Matcher m = VALID_PHONE_NUMBER_PATTERN.matcher(number);
    return m.matches();
  }

from intl_phone_number_input.

b02505048 avatar b02505048 commented on July 20, 2024

@natintosh Thanks for replying. Could we do the phone number validation outside the InternationalPhoneNumberInput?

I think this error message would occur when the user is typing the first digit number since isViablePhoneNumber function must have at least 2 digits?

from intl_phone_number_input.

natintosh avatar natintosh commented on July 20, 2024

Thanks for suggesting this, I will consider it for the next major update, but its chances are low.

from intl_phone_number_input.

marcomartinscastanho avatar marcomartinscastanho commented on July 20, 2024

Hello, I'm still having an issue with setState() inside onInputValidated().

When I tap the input area (to open the keyboard), I get this

W/IInputConnectionWrapper(24974): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper(24974): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper(24974): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper(24974): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper(24974): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper(24974): getTextAfterCursor on inactive InputConnection

Then when I type a 0 I get this

I/flutter (24974): +330
E/flutter (24974): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(NumberParseException, The string supplied is too short to be a phone number., null)
E/flutter (24974): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
E/flutter (24974): #1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:321:33)
E/flutter (24974): <asynchronous suspension>
E/flutter (24974): #2      PhoneNumberUtil.getRegionInfo (package:libphonenumber/libphonenumber.dart:61:51)
E/flutter (24974): #3      PhoneNumber.getRegionInfoFromPhoneNumber (package:intl_phone_number_input/src/utils/phone_number.dart:41:51)
E/flutter (24974): #4      PhoneNumber.getParsableNumber (package:intl_phone_number_input/src/utils/phone_number.dart:60:34)
E/flutter (24974): #5      _InputWidgetState.initialiseWidget (package:intl_phone_number_input/src/widgets/input_widget.dart:262:31)
E/flutter (24974): #6      _InputWidgetState.didUpdateWidget (package:intl_phone_number_input/src/widgets/input_widget.dart:251:7)
E/flutter (24974): #7      StatefulElement.update (package:flutter/src/widgets/framework.dart:4396:58)
E/flutter (24974): #8      Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
E/flutter (24974): #9      RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5161:32)
E/flutter (24974): #10     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5561:17)
E/flutter (24974): #11     Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
E/flutter (24974): #12     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5452:14)
E/flutter (24974): #13     Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
E/flutter (24974): #14     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
E/flutter (24974): #15     Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
E/flutter (24974): #16     StatelessElement.update (package:flutter/src/widgets/framework.dart:4298:5)
E/flutter (24974): #17     Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
E/flutter (24974): #18     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
E/flutter (24974): #19     Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
E/flutter (24974): #20     ProxyElement.update (package:flutter/src/widgets/framework.dart:4557:5)
E/flutter (24974): #21     Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
E/flutter (24974): #22     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
E/flutter (24974): #23     Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
E/flutter (24974): #24     ProxyElement.update (package:flutter/src/widgets/framework.dart:4557:5)
E/flutter (24974): #25     Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
E/flutter (24974): #26     RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5161:32)
E/flutter (24974): #27     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5561:17)
E/flutter (24974): #28     Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
E/flutter (24974): #29     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
E/flutter (24974): #30     Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
E/flutter (24974): #31     StatefulElement.update (package:flutter/src/widgets/framework.dart:4413:5)
E/flutter (24974): #32     Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
E/flutter (24974): #33     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
E/flutter (24974): #34     Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
E/flutter (24974): #35     ProxyElement.update (package:flutter/src/widgets/framework.dart:4557:5)
E/flutter (24974): #36     Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
E/flutter (24974): #37     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
E/flutter (24974): #38     Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
E/flutter (24974): #39     StatefulElement.update (package:flutter/src/widgets/framework.dart:4413:5)
E/flutter (24974): #40     Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
E/flutter (24974): #41     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5452:14)
E/flutter (24974): #42     Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
E/flutter (24974): #43     ComponentElement.performRebuild (package:flutter/src/widge

And if then I type any other number, onInputChange() goes into infinite loop and I can't type anything else anymore.

I'm using version ^0.4.6+2, which I think is the version that includes the fix to the original issue of this topic.

Btw, these are my parameters, in case it helps reproduce the error

            InternationalPhoneNumberInput(
              onInputChanged: (PhoneNumber number) {
                this.number = number;
                print(this.number.phoneNumber); //TODO: remove this line
              },
              onInputValidated: (bool value) {
                setState(() {
                  // activate/deactivate the Done button
                  isDoneEnabled = value;
                });
                
              },
              ignoreBlank: true,
              autoValidate: true,
              textStyle: TextStyle(fontSize: 20.0),
              selectorTextStyle: TextStyle(color: Colors.black, fontSize: 20.0),
              initialValue: number,
              textFieldController: controller,
              hintText: 'your phone number',
            ),

from intl_phone_number_input.

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.