首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有颤振的json_serializable封装的不良状态意外诊断

带有颤振的json_serializable封装的不良状态意外诊断
EN

Stack Overflow用户
提问于 2020-08-10 05:38:28
回答 3查看 2.6K关注 0票数 2

我试图在颤振应用程序中为我的模型自动生成json_serializable代码。

下面是我的模型的一个例子:

代码语言:javascript
复制
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

代码语言:javascript
复制
dev_dependencies:
  flutter_test:
    sdk: flutter
  build_runner:
  json_serializable:

在指挥下:

代码语言:javascript
复制
flutter packages pub run build_runner build

我有这个:

代码语言:javascript
复制
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.

我的颤音版信息:

代码语言:javascript
复制
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)

我已经尝试过不同版本的包和build_runner,但是同样的错误。

如何修复这个自动生成的转轮?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2020-08-10 06:28:44

我通过添加

代码语言:javascript
复制
dependency_overrides:
  analyzer: '0.39.14'

转到pubspec.yaml

票数 10
EN

Stack Overflow用户

发布于 2020-08-10 08:48:21

2个备选方案

将通道更改为dev (可用dart 2.10+ )

如前所述,添加

analyzer: '0.39.14'dependency_overrides

票数 2
EN

Stack Overflow用户

发布于 2020-11-06 14:40:46

对我来说,修复是升级analyzer: '0.39.15',我使用的是sdk: ">=2.10.0 <3.0.0"

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63334661

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档