Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
johnvuko opened this issue Aug 5, 2021 · 16 comments · Fixed by #439
Closed

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

johnvuko opened this issue Aug 5, 2021 · 16 comments · Fixed by #439

Comments

@johnvuko
Copy link

johnvuko commented Aug 5, 2021

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)

  • Android 11 - Samsung SM-G991B (RP1A.200720.012)
  • In French, so the number used is probably something like +33612345678 or +33712345678

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
Copy link

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 [email protected]: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
Copy link

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

@J-Dubon
Copy link

J-Dubon commented Jun 30, 2022

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

@tspoke
Copy link

tspoke commented Sep 13, 2022

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
Copy link

apackin commented Jan 18, 2023

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
Copy link

kdmny commented Feb 2, 2023

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
Copy link

kdmny commented Jun 20, 2023

This still appears to be an issue with 0.7.3+1

@SashaKrstev
Copy link

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
Copy link

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
Copy link

JoydS commented Dec 21, 2023

Hello guys,
Any update on this subject ?
Thanks

@BlakeTNC
Copy link

BlakeTNC commented Feb 1, 2024

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

I can confirm that these steps to reproduce do work: #245 (comment)

@jozunav
Copy link

jozunav commented Mar 8, 2024

This happens when the format has space

@iquirino
Copy link

@iquirino
Copy link

Maybe, this can help:
#425

@congnguyen-prismtech
Copy link

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
Copy link

iquirino commented Sep 9, 2024

Awesome, I'll test it as soon as possible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.