Flutter - source-gen 命令与配置

Flutter 通过 source-gen 生成对应的model类

1. 命令

  1. 引入 part ‘xxx.g.dart’; 生成对应 xxx.g.dart 文件
终端执行
1
flutter pub run build_runner clean && flutter pub run build_runner build --delete-conflicting-outputs
  1. 生成配置
根目录下新建文件 build.yaml
1
2
3
4
5
6
7
8
targets:
$default:
builders:
reflectable:
generate_for:
- test/**.dart
options:
formatted: true