【问题标题】:Flutter: pub finished with exit code 255Flutter:pub 以退出代码 255 结束
【发布时间】:2020-01-24 18:40:34
【问题描述】:

我正在通过构建运行器、json 模型和可序列化的 json 为我的颤振应用程序制作模型。但是我收到了这个错误

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

在我的 pubspec.yaml 文件中,我在开发依赖项中添加了这些颤振包:

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

我要为其制作模型的 Json 文件:

第一个 json 文件

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

第二个 Json 文件

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

你能帮我看看我在哪里做错了吗,为什么我在终端运行命令时会出现这个错误 flutter 包发布运行 json_model

【问题讨论】:

    标签: flutter serialization model dart-pub jsonmodel


    【解决方案1】:

    这为时已晚,但有人可能会使用它,这对我有用:

    我认为当您更改模型中的某些内容并运行 agin 时可能会发生这种情况

    flutter pub run build_runner build
    

    更新:

    运行它,它会为你完成这项工作:

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

    old : 所以首先尝试删除所有以

    结尾的生成文件

    XXX.g.dart

    然后运行

    flutter clean 
    

    然后

    flutter pub get
    

    终于

    flutter pub run build_runner build
    

    【讨论】:

    • 我花了一个小时,这是对我有用的解决方案。谢谢。
    • @Dennis 你可以运行这个,它会为你完成这项工作flutter pub run build_runner build --delete-conflicting-outputs
    • 我总是使用 --delete-conflicting-outputs 命令来节省时间,而不是在它指示后再次运行 build_runner。但我以前从未遇到过错误代码 255 的问题。所以手动删除 .g 文件是可行的。诡异的。 ?
    • 很高兴听到你的一切都很好,保持良好的工作@Dennis???
    【解决方案2】:

    检查您的 pubspec.yaml 文件。

    依赖:

      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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-26
      • 1970-01-01
      • 1970-01-01
      • 2014-01-04
      • 2017-11-03
      • 2017-01-19
      相关资源
      最近更新 更多