natintosh / intl_phone_number_input

MIT License
165 stars 502 forks source link

RangeError (index): Invalid value: Not in inclusive range 0..5: 6 #245

Closed johnvuko closed 3 weeks ago

johnvuko commented 3 years ago

Describe the bug I just have a report from Sentry, no information about how to reproduce.

Package version 0.7.0+2

Flutter version 2.2.3

To Reproduce Unknown, I just have the crash report from Sentry without anything else.

Expected behavior Not to bug.

Targeted platforms (please complete the following information)

Here the full crash report (no information from my own code strangely):

RangeError: RangeError (index): Invalid value: Not in inclusive range 0..6: 7
  File "string_patch.dart", line 255, in _StringBase.[]
  File "as_you_type_formatter.dart", line 55, in AsYouTypeFormatter.formatEditUpdate.<fn>
  File "zone.dart", line 1362, in _rootRunUnary

Here how to input is used:

        InternationalPhoneNumberInput(
          selectorConfig: SelectorConfig(
            selectorType: PhoneInputSelectorType.DIALOG,
          ),
          initialValue: state.phone,
          hintText: I18n.t('page.signup.field.phone'),
          onInputChanged: (value) {
            BlocProvider.of<SignupCubit>(context).updatePhone(value);
          },
        ) 
luckyhandler commented 2 years ago

I get the same via Crashlytics

Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: RangeError (index): Invalid value: Not in inclusive range 0..6: 9. Error thrown null.
       at _StringBase.[](_StringBase.java)
       at AsYouTypeFormatter.formatEditUpdate.<fn>(formatEditUpdate.java:55)

Package Version intl_phone_number_input: ^0.7.0+2

▶ flutter doctor -v
[✓] Flutter (Channel stable, 2.5.3, on macOS 12.0.1 21A559 darwin-x64, locale de-DE)
    • Flutter version 2.5.3 at /Users/me/Development/sdks/flutter
    • Upstream repository git@github.com:flutter/flutter.git
    • Framework revision 18116933e7 (vor 3 Wochen), 2021-10-15 10:46:35 -0700
    • Engine revision d3ea636dc5
    • Dart version 2.14.4

Device Brand:HTC Model:U11 Orientation: Portrait RAM free: 1.57 GB Disk free: 47.32 GB Operating system Version:Android 9 Orientation: Portrait Rooted:No

josemojena commented 2 years ago

I have the same error too because to enter for example letters on the phone field.

J-Dubon commented 2 years ago

Any solution for this problem? The same happens to me.

tspoke commented 2 years ago

I do not encounter a crash BUT in France the range includes +337 (not only +336) and isValid from callbacks is always false for a valid phone number like : +33708091011

apackin commented 1 year ago

We're seeing the same issue in Sentry with intl_phone_number_input: 0.7.1

Error is from the last line of code in this section of as_you_type_formatter.dart

int offset =
              newValue.selection.end == -1 ? 0 : newValue.selection.end;

          if (separatorChars.hasMatch(parsedText)) {
            String valueInInputIndex = parsedText[offset - 1];

Looks like it relates to having the cursor at the end of the input?

Error details:

RangeError: RangeError (index): Invalid value: Not in inclusive range 0..6: 7
  File "string_patch.dart", line 260, in _StringBase.[]
  File "as_you_type_formatter.dart", line 55, in AsYouTypeFormatter.formatEditUpdate.<fn>  

On multiple devices:

Device: OnePlus8Pro, Android 11 Device: iPhone 14, iOS 16.2

kdmny commented 1 year ago

I'm able to reliably reproduce on v0.7.1 and 0.7.2. Here's how:

  1. Setup
InternationalPhoneNumberInput(
  formatInput: true,
  onInputChanged: (PhoneNumber number) {},
);
  1. Select the US from country drop down
  2. Enter any 3 digits, enter a hyphen character, enter 3 more digits, enter a hyphen character
  3. Crash
I/flutter (25273): ----------------FIREBASE CRASHLYTICS----------------
I/flutter (25273): RangeError (index): Invalid value: Not in inclusive range 0..6: 7
I/flutter (25273): #0      _StringBase.[] (dart:core-patch/string_patch.dart:258:41)
I/flutter (25273): #1      AsYouTypeFormatter.formatEditUpdate.<anonymous closure> (package:intl_phone_number_input/src/utils/formatter/as_you_type_formatter.dart:54:50)
I/flutter (25273): <asynchronous suspension>
I/flutter (25273): ----------------------------------------------------

I'd guess the length of input needed to trigger the error occurs as a function of the country code and that, somewhere in the call stack, the program isn't expecting the user to be entering hyphens when formatInput is set to true.

From my experience, the error is fairly benign meaning it doesn't cause a fatal app crash. Still, it pollutes the error tracking tools with noise making it hard to separate the wheat from the chaff.

kdmny commented 1 year ago

This still appears to be an issue with 0.7.3+1

SashaKrstev commented 1 year ago

This is still happening. To reproduce, enter any non-digit character into the field. It gets parsed out, but the offset does not get updated and it throws a Range error.

As previously mentioned it happens in as_you_type_formatter.dart line 57 version 0.7.3+1

if (separatorChars.hasMatch(parsedText)) {
            String valueInInputIndex = parsedText[offset - 1];
...
luckyhandler commented 1 year ago

This is again a trending error for me in Crashlytics with version 0.7.3+1

This issue has 66 crash events affecting 42 users RangeError (index): Invalid value: Not in inclusive range 0..12: 14

JoydS commented 9 months ago

Hello guys, Any update on this subject ? Thanks

BlakeTNC commented 8 months ago

I got this same crash, the first time I tested the library.

I can confirm that these steps to reproduce do work: https://github.com/natintosh/intl_phone_number_input/issues/245#issuecomment-1413548171

jozunav commented 7 months ago

This happens when the format has space

iquirino commented 5 months ago

Exactly, I'm getting the issue with Brazilian Mobile Phone.

https://github.com/natintosh/intl_phone_number_input/blob/77a07089f5d1d0668898a37a15dd5f7e7cc524ec/lib/src/utils/formatter/as_you_type_formatter.dart#L56C53-L57C63

iquirino commented 5 months ago

Maybe, this can help: https://github.com/natintosh/intl_phone_number_input/pull/425

congnguyen-prismtech commented 3 months ago

I got the same. And i have found out the problem due to the user tap to the space character in phone number keyboard.

iquirino commented 3 weeks ago

Awesome, I'll test it as soon as possible