错误:没有为“AppBarTheme”类定义 getter“textTheme”。并且没有名为“accentColor”的命名参数

问题描述 投票:0回答:2
Running Gradle task 'assembleDebug'...
../../../.pub-cache/hosted/pub.dev/flutter_neumorphic-3.2.0/lib/src/widget/app_bar.dart:183:29: Error: The getter 'textTheme' isn't defined for the class 'AppBarTheme'.
 - 'AppBarTheme' is from 'package:flutter/src/material/app_bar_theme.dart' ('../../../MycodingLibs/flutter/packages/flutter/lib/src/material/app_bar_theme.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'textTheme'.
        style: (appBarTheme.textTheme?.headline5 ??
                            ^^^^^^^^^
../../../.pub-cache/hosted/pub.dev/flutter_neumorphic-3.2.0/lib/src/widget/app.dart:89:7: Error: No named parameter with the name 'accentColor'.
      accentColor: theme.variantColor,
      ^^^^^^^^^^^
../../../MycodingLibs/flutter/packages/flutter/lib/src/material/theme_data.dart:290:11: Context: Found this candidate, but the arguments don't match.
  factory ThemeData({
          ^
Target kernel_snapshot failed: Exception


FAILURE: Build failed with an exception.

* Where:
Script '/home/corecreater/MycodingLibs/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 1201

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/home/corecreater/MycodingLibs/flutter/bin/flutter'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 17s
Exception: Gradle task assembleDebug failed with exit code 1

在我看来这是一个老项目,我不知道该怎么办。 我尝试更新 pubspec.yaml 中的所有包。 根据 Android Studio,没有代码错误。 我认为这是flutter版本的问题。

android flutter dart flutter-dependencies
2个回答
0
投票

出现此错误是由于 flutter_neumorphic 和 Dart 3.0 之间的兼容性问题。要解决此问题,您可以使用替代包 flutter_neumorphic_plus(版本 ^3.3.0 或更高版本) 只需将其添加到 pubspec.yaml

flutter_neumorphic_plus: ^3.3.0

添加后而不是 import 'package:flutter_neumorphic/flutter_neumorphic.dart';

// import 'package:flutter_neumorphic/flutter_neumorphic.dart';
 import 'package:flutter_neumorphic_plus/flutter_neumorphic.dart';//add this

-1
投票

这可能是你的 flutter_neumorphic 包的问题,它可能是你在其他项目之前使用的。如果发生此问题,您可以在终端上运行此命令。

flutter pub cache clean

运行该命令后,您计算机上的 pub 缓存将被清除,之前下载的任何软件包都需要在需要时重新下载。

注意:如果您不使用 Flutter,可以将 'flutter pub cache clean' 替换为 'pub cache clean' 以清除常规 Dart 包的 pub 缓存。

© www.soinside.com 2019 - 2024. All rights reserved.