Flutter 颤振:为什么json_注释包不生成*.g.dart文件
我试图使用json_注释包序列化json对象,但它没有生成Flutter 颤振:为什么json_注释包不生成*.g.dart文件,flutter,dart,Flutter,Dart,我试图使用json_注释包序列化json对象,但它没有生成*.g.dart文件 我的pubspec.yaml文件 dependencies: flutter: sdk: flutter cupertino_icons: ^1.0.0 lottie: ^0.7.0+1 font_awesome_flutter: ^8.11.0 effective_dart: ^1.3.0 provider: ^4.3.3 http: ^0.12.2 dio: ^3.0.1
*.g.dart
文件
我的pubspec.yaml文件
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.0
lottie: ^0.7.0+1
font_awesome_flutter: ^8.11.0
effective_dart: ^1.3.0
provider: ^4.3.3
http: ^0.12.2
dio: ^3.0.10
connectivity: ^2.0.2
retrofit: ^1.3.4+1
json_annotation: ^3.1.1
dev_dependencies:
flutter_test:
sdk: flutter
retrofit_generator: ^1.4.1+2
build_runner: ^1.11.1
我的news.dart文件
import 'package:json_annotation/json_annotation.dart';
part 'news.g.dart';
@JsonSerializable()
class News {
Source source;
String author;
String title;
String description;
String url;
String urlToImage;
String publishedAt;
String content;
News(
{this.source,
this.author,
this.title,
this.description,
this.url,
this.urlToImage,
this.publishedAt,
this.content});
factory News.fromJson(Map<String, dynamic> json) => _$NewsFromJson(json);
}
@JsonSerializable()
class Source {
String id;
String name;
Source({this.id, this.name});
factory Source.fromJson(Map<String, dynamic> source) =>
_$SourceFromJson(source);
}
import'package:json_annotation/json_annotation.dart';
“新闻·g·达特”部分;
@JsonSerializable()
班级新闻{
来源;
字符串作者;
字符串标题;
字符串描述;
字符串url;
字符串urlToImage;
字符串数据;
字符串内容;
新闻(
{此来源,
这位作者,
这个名字,
这个.说明,,
这个.url,
这个.urlToImage,
这个.dat,
这是一种新方法(content});
factory News.fromJson(Map json)=>$NewsFromJson(json);
}
@JsonSerializable()
类源{
字符串id;
字符串名;
源({this.id,this.name});
factory Source.fromJson(映射源)=>
_$SourceFromJson(source);
}
我用这个命令生成文件
颤振酒吧跑步构建(跑步构建)
我在我的另一个项目中也做了同样的工作,它工作得很好,但在这里它不工作,所以如果你想使用json_注释包,那么你还需要json_序列化包,所以我只需要添加该包,然后它就会工作