Плохое состояние Неожиданная диагностика пакета json_serializable с флаттером

Я пытаюсь автоматически сгенерировать json_serializable код для моих моделей в приложении flutter.

Вот пример моей модели:

import 'package:propro/src/models/product_model.dart';
import 'package:propro/src/models/user/address_model.dart';
import 'package:propro/src/models/user/membership_model.dart';
import 'package:propro/src/models/user/review_model.dart';
import 'package:propro/src/models/user/setting_model.dart';
import 'package:json_annotation/json_annotation.dart';

part 'user_model.g.dart';

@JsonSerializable(explicitToJson: true)
class User {
  final String uid;
  final String email;
  final String password;
  final String firstName;
  final String lastName;
  final String gender;
  final List<Address> addresses;
  final List<Review> reviews;
  final List<Product> wishlist;
  final Membership membership;
  final Setting setting;

  User({
    this.uid,
    this.email,
    this.password,
    this.firstName,
    this.lastName,
    this.gender,
    this.addresses,
    this.reviews,
    this.wishlist,
    this.membership,
    this.setting,
  });

  factory User.fromJson(Map<String, dynamic> json) => _UserFromJson(json);

  Map<String, dynamic> toJson() => _UserToJson(this);
}

Вот мой pubspec.yaml

dev_dependencies:
  flutter_test:
    sdk: flutter
  build_runner:
  json_serializable:

И с командой:

flutter packages pub run build_runner build

У меня есть это:

PS C:\tofiq\fp\propro> flutter packages pub run build_runner build
[INFO] Generating build script...
[INFO] Generating build script completed, took 755ms

[WARNING] Deleted previous snapshot due to missing asset graph.
[INFO] Creating build script snapshot......
[INFO] Creating build script snapshot... completed, took 22.3s

[INFO] Initializing inputs
[INFO] Building new asset graph...
[INFO] Building new asset graph completed, took 1.1s   

[INFO] Checking for unexpected pre-existing outputs....
[INFO] Checking for unexpected pre-existing outputs. completed, took 2ms

[INFO] Running build...
[INFO] Generating SDK summary...
[SEVERE] json_serializable:json_serializable on lib/main.dart:

Bad state: Unexpected diagnostics:
C:\tofiq\flutter\bin\cache\pkg\sky_engine\lib\ui\channel_buffers.dart:119:41 - This requires the 'non-nullable' language feature to be enabled.
C:\tofiq\flutter\bin\cache\pkg\sky_engine\lib\ui\channel_buffers.dart:152:17 - This requires the 'non-nullable' language feature to be enabled.
C:\tofiq\flutter\bin\cache\pkg\sky_engine\lib\ui\channel_buffers.dart:88:62 - This requires the 'non-nullable' language feature to be enabled. 
C:\tofiq\flutter\bin\cache\pkg\sky_engine\lib\ui\channel_buffers.dart:153:38 - This requires the 'non-nullable' language feature to be enabled.
C:\tofiq\flutter\bin\cache\pkg\sky_engine\lib\ui\channel_buffers.dart:186:51 - This requires the 'non-nullable' language feature to be enabled.
C:\tofiq\flutter\bin\cache\pkg\sky_engine\lib\ui\channel_buffers.dart:133:32 - This requires the 'non-nullable' language feature to be enabled.
C:\tofiq\flutter\bin\cache\pkg\sky_engine\lib\ui\channel_buffers.dart:154:25 - This requires the 'non-nullable' language feature to be enabled.
C:\tofiq\flutter\bin\cache\pkg\sky_engine\lib\ui\channel_buffers.dart:18:17 - This requires the 'non-nullable' language feature to be enabled. 
C:\tofiq\flutter\bin\cache\pkg\sky_engine\lib\ui\channel_buffers.dart:64:4 - This requires the 'non-nullable' language feature to be enabled.  
C:\tofiq\flutter\bin\cache\pkg\sky_engine\lib\ui\channel_buffers.dart:168:32 - This requires the 'non-nullable' language feature to be enabled.
C:\tofiq\flutter\bin\cache\pkg\sky_engine\lib\ui\channel_buffers.dart:47:14 - This requires the 'non-nullable' language feature to be enabled. 
C:\tofiq\flutter\bin\cache\pkg\sky_engine\lib\ui\channel_buffers.dart:159:38 - This requires the 'non-nullable' language feature to be enabled.
C:\tofiq\flutter\bin\cache\pkg\sky_engine\lib\ui\channel_buffers.dart:132:37 - This requires the 'non-nullable' language feature to be enabled.
C:\tofiq\flutter\bin\cache\pkg\sky_engine\lib\ui\channel_buffers.dart:118:48 - This requires the 'non-nullable' language feature to be enabled.
C:\tofiq\flutter\bin\cache\pkg\sky_engine\lib\ui\channel_buffers.dart:19:11 - This requires the 'non-nullable' language feature to be enabled. 
[SEVERE] json_serializable:json_serializable on lib/main.dart:
[INFO] 5.7s elapsed, 1/17 actions completed.
[INFO] 6.8s elapsed, 1/17 actions completed.
[INFO] 7.8s elapsed, 1/17 actions completed.
[INFO] 8.9s elapsed, 1/17 actions completed.
[INFO] 10.0s elapsed, 1/17 actions completed.
[INFO] 11.0s elapsed, 1/17 actions completed.
[INFO] 12.1s elapsed, 1/17 actions completed.

И информация о моей версии флаттера:

PS C:\tofiq\fp\propro> flutter upgrade
Flutter is already up to date on channel beta
Flutter 1.20.0 • channel beta • https://github.com/flutter/flutter.git
Framework • revision 916c3ac648 (9 days ago) • 2020-08-01 09:01:12 -0700
Engine • revision d6ee1499c2
Tools • Dart 2.9.0 (build 2.9.0-21.10.beta)

Я уже пробовал использовать разные версии package и build_runner, но с той же ошибкой.

Как я могу исправить эту автоматическую генерацию бегуна?

2 ответа

Решение

Я решил эту проблему добавлением

dependency_overrides:
  analyzer: '0.39.14'

в pubspec.yaml

2 варианта

изменить канал на dev (где доступен dart 2.10+)

или

как упоминалось ранее, добавьте

analyzer: '0.39.14' к dependency_overrides раздел

Для меня исправление было обновлением analyzer: '0.39.15'Я использую sdk: ">=2.10.0 <3.0.0"

Другие вопросы по тегам