我找到了解决方案。这是非常接近igokom的答案。
targets:
$default:
builders:
auto_route_generator|autoRouteGenerator:
enabled: true
generate_for:
include:
- lib/infrastructure/routes/app_routes.routes.dart
# [exclude] is not needed if at least one path is provided
# in [include]. It will only target [include]d paths
# exclude:
# - ...
json_serializable:
enabled: true
generate_for:
include:
- lib/**.model.dart
- lib/**_bloc.dart
- lib/**_cubit.dart
options:
explicit_to_json: true
include_if_null: false
freezed|freezed:
enabled: true
generate_for:
include:
- lib/**.model.dart
- lib/**_bloc.dart
- lib/**_cubit.dart
injectable_generator|injectable_builder:
enabled: true
generate_for:
include:
- lib/**_bloc.dart
- lib/**_cubit.dart
- lib/**.dao.dart
injectable_generator|injectable_config_builder:
enabled: true
generate_for:
include:
- lib/infrastructure/injection/injection.dart
我之前收到警告,内容为
[WARNING] Configuring 'auto_route_generator:auto_route_generator' in target 'my_app:my_app' but this is not a known Builder
我收到此错误是因为生成器的名称auto_route
不是auto_route_generator
,而是autoRouteGenerator
。
这些值可以在插件build.yaml
文件中找到
builders:
# [autoRouteGenerator] is the name of the generator
# that needs to be referenced
autoRouteGenerator:
import: "package:auto_route_generator/builder.dart"
builder_factories: ["autoRouteGenerator"]
build_extensions: {'.dart': ['.gr.dart']}
auto_apply: dependents
build_to: source
可以在“$definingPackageName:$targetname”中引用目标。当目标名称与包名称匹配时,它也可以仅称为包名称。每个包中的一个目标必须使用包名称,以便消费者默认使用它。在 build.yaml 文件中,可以使用键 $default 或包的名称来定义此目标。
您可以在此处找到有关它的更多信息,这是一篇非常好的文章,为build.yaml
文件提供了一些很好的提示