4

I am making models for my flutter application via build runner,json model and json serializable. But i got this error

Unhandled exception:
RangeError (index): Invalid value: Valid value range is empty: 0
#0      _StringBase.[] (dart:core-patch/string_patch.dart:247:55)
#1      changeFirstChar (file:///C:/flutter/.pub-cache/hosted/pub.dartlang.org/json_model-0.0.2/bin/json_model.dart:89:41)
#2      getType (file:///C:/flutter/.pub-cache/hosted/pub.dartlang.org/json_model-0.0.2/bin/json_model.dart:116:20)
#3      walk.<anonymous closure>.<anonymous closure> (file:///C:/flutter/.pub-cache/hosted/pub.dartlang.org/json_model-0.0.2/bin/json_model.dart:62:23)
#4      _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:379:8)
#5      walk.<anonymous closure> (file:///C:/flutter/.pub-cache/hosted/pub.dartlang.org/json_model-0.0.2/bin/json_model.dart:50:37)
#6      List.forEach (dart:core-patch/growable_array.dart:282:8)
#7      walk (file:///C:/flutter/.pub-cache/hosted/pub.dartlang.org/json_model-0.0.2/bin/json_model.dart:38:8)
#8      main (file:///C:/flutter/.pub-cache/hosted/pub.dartlang.org/json_model-0.0.2/bin/json_model.dart:18:6)
#9      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:299:32)
#10     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
pub finished with exit code 255

In my pubspec.yaml file i added these flutter packages in dev dependencies:

dev_dependencies:
  flutter_test:
    sdk: flutter
  json_model: ^0.0.2
  json_serializable:
  build_runner:

My Json files for which i want to make models:

1st json file

{
  "id": 1,
  "country": "Australia",
  "currencySymbol": "$"
}

2nd Json file

{
  "currencylist": "$[]currency"
}

Can you please help me where i am doing wrong in this and why i am getting this error when i run command in terminal flutter packages pub run json_model.

Umair
  • 1,759
  • 6
  • 23
  • 44

4 Answers4

8

this is too late but someone might get use of it, this worked for me:

I think this might happen when you change something in your model and you run agin

flutter pub run build_runner build

update:

run this and it will do the job for you:

flutter pub run build_runner build  --delete-conflicting-outputs 

old : so first try to delete all generated files that ends with

XXX.g.dart

and run

flutter clean 

then

flutter pub get

Finally

flutter pub run build_runner build
Baraa Aljabban
  • 992
  • 13
  • 22
  • I spent an hour and this is the solution worked for me. Thank you. – Dennis Jun 30 '20 at 14:26
  • @Dennis you might run this one and it will do the job for you `flutter pub run build_runner build --delete-conflicting-outputs` – Baraa Aljabban Jul 04 '20 at 10:59
  • I always use --delete-conflicting-outputs command to save time instead of running build_runner again after it instructs. But I never faced the problem with error code 255 before. So manually deleting the .g files worked. Weird. – Dennis Jul 06 '20 at 12:17
  • Glad to hear every thing is working fine for you, keep the good work @Dennis – Baraa Aljabban Jul 08 '20 at 03:06
  • flutter pub run build_runner build --delete-conflicting-outputs -- It still failing for me. – Apparao Mulpuri Oct 13 '22 at 14:29
1

You can simple run the

1.flutter clean.
2.flutter pub get.

This saves my several hours.

0

Check your pubspec.yaml file.

dependencies:

  json_annotation: ^2.0.0

dev_dependencies:

  json_model: //it is required to add for your error
  build_runner: ^1.0.0
  json_serializable: ^2.0.0
Elletlar
  • 3,136
  • 7
  • 32
  • 38
poonam kalra
  • 135
  • 2
  • 8
0

The problem could be easier than it seems. It may tell you an authentication error that refers to the "certificate_password" in "msix_config".

Being a data that is not recommended to push or register, it may be overlooked to place the correct data of the certificate in case you are using it.

enter image description here

ray
  • 11,310
  • 7
  • 18
  • 42
DARKATOV
  • 11
  • 1
  • 4