【问题标题】:Bad state: Unexpected diagnostics: Expected an identifier. [SEVERE] json_serializable:json_serializable on test/widget_test.dart错误状态:意外诊断:需要标识符。 [严重] json_serializable:json_serializable 在 test/widget_test.dart
【发布时间】:2021-01-06 10:16:57
【问题描述】:

Json 可序列化不工作我如何解决这个我不知道这个错误。我使用了颤振 build_runner:^1.7.2 json_serializable: ^3.4.1 分析器:^0.39.17 json_annotation:^3.0.1 没有一个文件正在创建 json

Json 可序列化不工作我如何解决这个我不知道这个错误。我使用了颤振 build_runner:^1.7.2 json_serializable: ^3.4.1 分析器:^0.39.17 json_annotation:^3.0.1 没有一个文件正在创建 json

 import 'package:dance/models/tutorials-model/video-data.dart';
 import 'package:json_annotation/json_annotation.dart';
    
part 'metadata.g.dart';

@JsonSerializable()
class MetaData {
  final String category;
  final String categoryId;
  final List<VideoData> data;

  MetaData(this.category, this.categoryId, this.data);

  factory MetaData.fromJson(Map<String, dynamic> json) => _$MetaDataFromJson(json);
  Map<String, dynamic> toJson() => _$MetaDataToJson(this);
}

------------------------terminal------------------------

flutter pub run build_runner watch

[INFO] Running build...
[INFO] Generating SDK summary...
[SEVERE] json_serializable:json_serializable on test/widget_test.dart:

Bad state: Unexpected diagnostics:
C:\Users\Admin\Desktop\flutter-dart\flutter\bin\cache\dart-sdk\lib\core\uri.dart:3259:39 - Expected an identifier.
[SEVERE] json_serializable:json_serializable on test/widget_test.dart:

Bad state: Unexpected diagnostics:
C:\Users\Admin\Desktop\flutter-dart\flutter\bin\cache\dart-sdk\lib\core\uri.dart:3259:39 - Expected an identifier.
[SEVERE] json_serializable:json_serializable on test/widget_test.dart:

Bad state: Unexpected diagnostics:
C:\Users\Admin\Desktop\flutter-dart\flutter\bin\cache\dart-sdk\lib\core\uri.dart:3259:39 - Expected an identifier.
[SEVERE] json_serializable:json_serializable on test/widget_test.dart:

Bad state: Unexpected diagnostics:
C:\Users\Admin\Desktop\flutter-dart\flutter\bin\cache\dart-sdk\lib\core\uri.dart:3259:39 - Expected an identifier.
[SEVERE] json_serializable:json_serializable on test/widget_test.dart:

Bad state: Unexpected diagnostics:
C:\Users\Admin\Desktop\flutter-dart\flutter\bin\cache\dart-sdk\lib\core\uri.dart:3259:39 - Expected an identifier.
[SEVERE] json_serializable:json_serializable on test/widget_test.dart:

Bad state: Unexpected diagnostics:
C:\Users\Admin\Desktop\flutter-dart\flutter\bin\cache\dart-sdk\lib\core\uri.dart:3259:39 - Expected an identifier.
[SEVERE] json_serializable:json_serializable on test/widget_test.dart:

Bad state: Unexpected diagnostics:
C:\Users\Admin\Desktop\flutter-dart\flutter\bin\cache\dart-sdk\lib\core\uri.dart:3259:39 - Expected an identifier.
[SEVERE] json_serializable:json_serializable on test/widget_test.dart:

Bad state: Unexpected diagnostics:
C:\Users\Admin\Desktop\flutter-dart\flutter\bin\cache\dart-sdk\lib\core\uri.dart:3259:39 - Expected an identifier.
[SEVERE] json_serializable:json_serializable on test/widget_test.dart:

Bad state: Unexpected diagnostics:
C:\Users\Admin\Desktop\flutter-dart\flutter\bin\cache\dart-sdk\lib\core\uri.dart:3259:39 - Expected an identifier.
[SEVERE] json_serializable:json_serializable on test/widget_test.dart:

Bad state: Unexpected diagnostics:
C:\Users\Admin\Desktop\flutter-dart\flutter\bin\cache\dart-sdk\lib\core\uri.dart:3259:39 - Expected an identifier.
[SEVERE] json_serializable:json_serializable on test/widget_test.dart:

Bad state: Unexpected diagnostics:
C:\Users\Admin\Desktop\flutter-dart\flutter\bin\cache\dart-sdk\lib\core\uri.dart:3259:39 - Expected an identifier.
[SEVERE] json_serializable:json_serializable on test/widget_test.dart:

Bad state: Unexpected diagnostics:
C:\Users\Admin\Desktop\flutter-dart\flutter\bin\cache\dart-sdk\lib\core\uri.dart:3259:39 - Expected an identifier.
[SEVERE] json_serializable:json_serializable on test/widget_test.dart:

Bad state: Unexpected diagnostics:
C:\Users\Admin\Desktop\flutter-dart\flutter\bin\cache\dart-sdk\lib\core\uri.dart:3259:39 - Expected an identifier.
[SEVERE] json_serializable:json_serializable on test/widget_test.dart:

Bad state: Unexpected diagnostics:
C:\Users\Admin\Desktop\flutter-dart\flutter\bin\cache\dart-sdk\lib\core\uri.dart:3259:39 - Expected an identifier.
[SEVERE] json_serializable:json_serializable on test/widget_test.dart:

Bad state: Unexpected diagnostics:
C:\Users\Admin\Desktop\flutter-dart\flutter\bin\cache\dart-sdk\lib\core\uri.dart:3259:39 - Expected an identifier.
[SEVERE] json_serializable:json_serializable on test/widget_test.dart:

Bad state: Unexpected diagnostics:
C:\Users\Admin\Desktop\flutter-dart\flutter\bin\cache\dart-sdk\lib\core\uri.dart:3259:39 - Expected an identifier.
[SEVERE] json_serializable:json_serializable on test/widget_test.dart:

Bad state: Unexpected diagnostics:
C:\Users\Admin\Desktop\flutter-dart\flutter\bin\cache\dart-sdk\lib\core\uri.dart:3259:39 - Expected an identifier.
[INFO] 2.3s elapsed, 1/17 actions completed.
[INFO] 3.4s elapsed, 1/17 actions completed.
[INFO] 4.4s elapsed, 1/17 actions completed.
[INFO] 5.4s elapsed, 1/17 actions completed.
[INFO] 6.4s elapsed, 1/17 actions completed.
[INFO] 7.4s elapsed, 1/17 actions completed.
[INFO] 8.4s elapsed, 1/17 actions completed.
[INFO] 9.4s elapsed, 1/17 actions completed.
[INFO] 10.5s elapsed, 1/17 actions completed.
[INFO] 11.5s elapsed, 1/17 actions completed.
[INFO] 12.5s elapsed, 1/17 actions completed.
[INFO] 13.5s elapsed, 1/17 actions completed.
[INFO] 14.5s elapsed, 1/17 actions completed.
[INFO] 15.5s elapsed, 1/17 actions completed.
[WARNING] No actions completed for 15.0s, waiting on:
  - json_serializable:json_serializable on lib/constants/constants.dart
  - json_serializable:json_serializable on lib/constants/key_provider.dart
  - json_serializable:json_serializable on lib/constants/routes_name.dart
  - json_serializable:json_serializable on lib/constants/url_provider.dart
  - json_serializable:json_serializable on lib/extension/string_extension.dart
  .. and 11 more

【问题讨论】:

标签: flutter dart jsonserializer


【解决方案1】:

我遇到了类似的冻结问题。 可以通过指定包来解决。


dependencies:
  analyzer: ^0.39.14 <- This

dev_dependencies:
  build_runner: ^1.10.0 <- This

重建前清理

# delete pubspec.lock
$ rm -rf pubspec.lock

# clean
$ flutter clean

参见。 https://github.com/flutter/flutter/issues/63096

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-15
    • 2020-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多