intl_phone_number_input icon indicating copy to clipboard operation
intl_phone_number_input copied to clipboard

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

Open jonathantribouharet opened this issue 2 years ago • 15 comments

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);
          },
        ) 

jonathantribouharet avatar Aug 05 '21 11:08 jonathantribouharet

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

luckyhandler avatar Nov 05 '21 20:11 luckyhandler

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

josemojena avatar Jan 25 '22 11:01 josemojena

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

J-Dubon avatar Jun 30 '22 20:06 J-Dubon

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

tspoke avatar Sep 13 '22 11:09 tspoke

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

apackin avatar Jan 18 '23 18:01 apackin

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 avatar Feb 02 '23 10:02 kdmny

This still appears to be an issue with 0.7.3+1

kdmny avatar Jun 20 '23 13:06 kdmny

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];
...

SashaKrstev avatar Aug 29 '23 11:08 SashaKrstev

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

luckyhandler avatar Sep 28 '23 07:09 luckyhandler

Hello guys, Any update on this subject ? Thanks

JoydS avatar Dec 21 '23 16:12 JoydS

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

BlakeTNC avatar Feb 01 '24 01:02 BlakeTNC

This happens when the format has space

jozunav avatar Mar 08 '24 21:03 jozunav

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 avatar Apr 10 '24 09:04 iquirino

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

iquirino avatar Apr 10 '24 12:04 iquirino

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

congnguyen-prismtech avatar Jun 28 '24 04:06 congnguyen-prismtech