Uma*_*air 4 serialization model dart-pub jsonmodel flutter
我正在通过构建运行器、json 模型和 json 可序列化为我的 flutter 应用程序制作模型。但我收到了这个错误
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
Run Code Online (Sandbox Code Playgroud)
在我的 pubspec.yaml 文件中,我在开发依赖项中添加了这些 flutter 包:
dev_dependencies:
flutter_test:
sdk: flutter
json_model: ^0.0.2
json_serializable:
build_runner:
Run Code Online (Sandbox Code Playgroud)
我想要为其制作模型的 Json 文件:
第一个 json 文件
{
"id": 1,
"country": "Australia",
"currencySymbol": "$"
}
Run Code Online (Sandbox Code Playgroud)
第二个 Json 文件
{
"currencylist": "$[]currency"
}
Run Code Online (Sandbox Code Playgroud)
您能否帮助我解决我在这方面做错的地方以及为什么当我在终端 flutter packages pub run json_model中运行命令时出现此错误。
这已经太晚了,但有人可能会使用它,这对我有用:
我认为当您更改模型中的某些内容并重新运行时可能会发生这种情况
flutter pub run build_runner build
Run Code Online (Sandbox Code Playgroud)
更新:
运行它,它会为你完成工作:
flutter pub run build_runner build --delete-conflicting-outputs
Run Code Online (Sandbox Code Playgroud)
old :所以首先尝试删除所有生成的以结尾的文件
XXX.g.dart
并运行
flutter clean
Run Code Online (Sandbox Code Playgroud)
然后
flutter pub get
Run Code Online (Sandbox Code Playgroud)
最后
flutter pub run build_runner build
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13456 次 |
| 最近记录: |