小编Pok*_*oom的帖子

Flutter:为什么 json_annotation 包没有生成 *.g.dart 文件

我正在尝试使用 json_annotation 包序列化 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.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
Run Code Online (Sandbox Code Playgroud)

我的 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, …
Run Code Online (Sandbox Code Playgroud)

dart flutter

6
推荐指数
1
解决办法
1654
查看次数

标签 统计

dart ×1

flutter ×1