0

我正在开发一个允许您Theme在 Flutter 中创建自定义的包。为此,我使用代码生成来创建您提供和访问自定义主题所需的所有必要类。

我已经遵循了几个关于代码生成的教程,并让它工作得非常快。但是现在我遇到了我不理解的奇怪行为。

正如教程所解释的,创建两个包是常见的做法:

  1. 一个用于保存注释。(应该作为依赖添加)
  2. 一个用于固定发电机。(应添加为开发依赖项)

所以这就是我所做的。在示例项目中,我添加了包并创建了以下自定义主题。

@ExtendedTheme()
class MyThemeData extends ExtendedThemeData {
  final Color myCustomColor;

  MyThemeData({
    required ThemeData themeData,
    required this.myCustomColor,
  }) : super(themeData: themeData);
}

我面临的问题是,当我扩展的类 ( ExtendedThemeData) 存在于当前包中时,一切正常。

但是我希望这个类成为包的一部分,所以我希望它成为注释包的一部分(因为生成器包应该只是一个开发依赖项)。

但是当我这样做时,生成器会因以下错误而中断(这只是结束,但有很多类似的东西):

 - '_AboutProgram' is from 'package:flutter/src/material/about.dart' ('../../../Development/flutter/packages/flutter/lib/src/material/about.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'TextAlign'.
            textAlign: TextAlign.center,
                       ^^^^^^^^^
../../../Development/flutter/packages/flutter/lib/src/material/about.dart:567:24: Error: The getter 'TextAlign' isn't defined for the class '_AboutProgram'.
 - '_AboutProgram' is from 'package:flutter/src/material/about.dart' ('../../../Development/flutter/packages/flutter/lib/src/material/about.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'TextAlign'.
            textAlign: TextAlign.center,
                       ^^^^^^^^^
../../../Development/flutter/packages/flutter/lib/src/material/about.dart:573:24: Error: The getter 'TextAlign' isn't defined for the class '_AboutProgram'.
 - '_AboutProgram' is from 'package:flutter/src/material/about.dart' ('../../../Development/flutter/packages/flutter/lib/src/material/about.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'TextAlign'.
            textAlign: TextAlign.center,
                       ^^^^^^^^^
../../../Development/flutter/packages/flutter/lib/src/material/about.dart:626:67: Error: Method not found: 'Size.fromWidth'.
                          constraints: BoxConstraints.loose(const Size.fromWidth(600.0)),
                                                                  ^^^^^^^^^
../../../Development/flutter/packages/flutter/lib/src/material/about.dart:801:23: Error: The method 'hashValues' isn't defined for the class '_DetailArguments'.
 - '_DetailArguments' is from 'package:flutter/src/material/about.dart' ('../../../Development/flutter/packages/flutter/lib/src/material/about.dart').
Try correcting the name to the name of an existing method, or defining a method named 'hashValues'.
  int get hashCode => hashValues(packageName, hashList(licenseEntries));
                      ^^^^^^^^^^
../../../Development/flutter/packages/flutter/lib/src/material/about.dart:801:47: Error: The method 'hashList' isn't defined for the class '_DetailArguments'.
 - '_DetailArguments' is from 'package:flutter/src/material/about.dart' ('../../../Development/flutter/packages/flutter/lib/src/material/about.dart').
Try correcting the name to the name of an existing method, or defining a method named 'hashList'.
  int get hashCode => hashValues(packageName, hashList(licenseEntries));
                                              ^^^^^^^^
../../../Development/flutter/packages/flutter/lib/src/material/about.dart:866:52: Error: Getter not found: 'FontWeight'.
                style: const TextStyle(fontWeight: FontWeight.bold),
                                                   ^^^^^^^^^^
../../../Development/flutter/packages/flutter/lib/src/material/about.dart:867:28: Error: The getter 'TextAlign' isn't defined for the class '_PackageLicensePageState'.
 - '_PackageLicensePageState' is from 'package:flutter/src/material/about.dart' ('../../../Development/flutter/packages/flutter/lib/src/material/about.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'TextAlign'.
                textAlign: TextAlign.center,
                           ^^^^^^^^^
../../../Development/flutter/packages/flutter/lib/src/material/about.dart:924:55: Error: Method not found: 'Size.fromWidth'.
              constraints: BoxConstraints.loose(const Size.fromWidth(600.0)),
                                                      ^^^^^^^^^
../../../Development/flutter/packages/flutter/lib/src/material/about.dart:926:31: Error: Method not found: 'Locale'.
                locale: const Locale('en', 'US'),
                              ^^^^^^
../../../Development/flutter/packages/flutter/lib/src/material/about.dart:955:33: Error: Method not found: 'Locale'.
                  locale: const Locale('en', 'US'),
                                ^^^^^^
../../../Development/flutter/packages/flutter/lib/src/material/about.dart:1535:36: Error: Method not found: 'Size.fromHeight'.
              preferredSize: const Size.fromHeight(kToolbarHeight),
                                   ^^^^^^^^^^
../../../Development/flutter/packages/flutter/lib/src/material/about.dart:1654:56: Error: Getter not found: 'Radius'.
              borderRadius: BorderRadius.vertical(top: Radius.circular(3.0), bottom: Radius.zero),
                                                       ^^^^^^
../../../Development/flutter/packages/flutter/lib/src/material/about.dart:1654:63: Error: Method invocation is not a constant expression.
              borderRadius: BorderRadius.vertical(top: Radius.circular(3.0), bottom: Radius.zero),
                                                              ^^^^^^^^
../../../Development/flutter/packages/flutter/lib/src/material/about.dart:1654:86: Error: Getter not found: 'Radius'.
              borderRadius: BorderRadius.vertical(top: Radius.circular(3.0), bottom: Radius.zero),
                                                                                     ^^^^^^
../../../Development/flutter/packages/flutter/lib/src/material/about.dart:1651:27: Error: The getter 'Clip' isn't defined for the class '_DetailView'.
 - '_DetailView' is from 'package:flutter/src/material/about.dart' ('../../../Development/flutter/packages/flutter/lib/src/material/about.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'Clip'.
            clipBehavior: Clip.antiAlias,
                          ^^^^
[INFO] Precompiling build script... completed, took 6.3s

[SEVERE] Failed to precompile build script .dart_tool/build/entrypoint/build.dart.
This is likely caused by a misconfigured builder definition.

我错过了什么吗?为什么当类在同一个包中时它可以工作,而不是当我从 annotations 包中引用它时?

4

0 回答 0