Flutter 开发技巧 AI 快速构建 json_annotation model 的提示词

  1. 将下面这段复制到AI
    GPT、DeepSeek 、文心快码 试过效果都可以,不用做任何更改。
  2. 将 json 数据丢给 AI 就行了
bash 复制代码
我会提供一段 JSON 数据,请帮我生成 Dart 模型,要求严格如下:

1. 使用 json_annotation 包,包含:
   - @JsonSerializable()
   - part 'xxx.g.dart';
   - fromJson / toJson 方法

2. 构造函数必须是这种形式:
   ClassName({ this.xxx, this.yyy });

3. 字段要求:
   - **严格保持 JSON 中的字段命名,不要改动,不要转成驼峰命名**
   - 每个字段必须是可空类型(int?、String?、List<T>?)
   - 每个字段写简短注释(根据字段含义)

4. 如果 JSON 有嵌套对象或数组,必须拆分成独立 model 文件,并互相引用。

5. 输出时只给 Dart 代码,不要解释。

6. 代码风格必须与下面示例完全一致:

```dart
import 'package:json_annotation/json_annotation.dart';

part 'example_model.g.dart';

@JsonSerializable()
class ExampleModel {
  ExampleModel({
    this.id,
    this.name,
  });

  factory ExampleModel.fromJson(Map<String, dynamic> json) =>
      _$ExampleModelFromJson(json);

  int? id; // ID
  String? name; // 名称

  Map<String, dynamic> toJson() => _$ExampleModelToJson(this);
}
相关推荐
传奇开心果编程8 小时前
【Flutter入门练中学】第2课:布局系统
学习·flutter·ui
君赏13 小时前
FlutterPatch:把 Shorebird 热更新的控制面搬回自己服务器
flutter
用户21816970493016 小时前
Flutter tootip 轻量级提示
flutter
用户21816970493017 小时前
Flutter 拖拽 Draggable DragTarget
flutter
yume_sibai17 小时前
05-Flutter实战项目
前端·flutter
天若有情67318 小时前
独立开发复盘:我用 Node.js 做了个在线工具箱
前端·json·工具
传奇开心果编程18 小时前
【Flutter入门练中学】第1课:从零开始
学习·flutter·ui
Asurplus1 天前
【SpringBoot4】3、从SpringBoot4升级Sa-Token1.46.0报错
redis·sa-token·json·jackson·springboot4
用户2181697049301 天前
Flutter ClipPath
flutter
代码中介商1 天前
C++ 预约系统实战(三):服务端实现——libevent 事件驱动与业务路由
c++·json·c/s