Flutter 无法运行,get_navigation & 主题错误

Posted

技术标签:

【中文标题】Flutter 无法运行,get_navigation & 主题错误【英文标题】:Flutter not able to run, get_navigation & theme error 【发布时间】:2021-02-18 16:30:24 【问题描述】:

我实际上是在尝试运行我的应用程序,但我遇到了这个错误:

Running "flutter pub get" in riverpod_stacked_app...
Launching lib/main.dart on sdk gphone x86 arm in debug mode...
Running Gradle task 'assembleDebug'...
../../.pub-cache/hosted/pub.dartlang.org/get-3.15.0/lib/get_navigation/src/extension_navigation.dart:235:37: Error: No named parameter with the name 'shadowThemeOnly'.
    final theme = Theme.of(context, shadowThemeOnly: true);
                                    ^^^^^^^^^^^^^^^
../../development/flutter/packages/flutter/lib/src/material/theme.dart:119:20: Context: Found this candidate, but the arguments don't match.
  static ThemeData of(BuildContext context) 
                   ^^
../../.pub-cache/hosted/pub.dartlang.org/get-3.15.0/lib/get_navigation/src/extension_navigation.dart:431:43: Error: No named parameter with the name 'shadowThemeOnly'.
      theme: Theme.of(key.currentContext, shadowThemeOnly: true),
                                          ^^^^^^^^^^^^^^^
../../development/flutter/packages/flutter/lib/src/material/theme.dart:119:20: Context: Found this candidate, but the arguments don't match.
  static ThemeData of(BuildContext context) 
                   ^^


FAILURE: Build failed with an exception.

* Where:
Script '/Users/Alex/development/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 900

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/Users/Alex/development/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 19s
Exception: Gradle task assembleDebug failed with exit code 1

我不明白为什么它不能构建。我没有看到这两个错误之间的联系:

get_navigation 以 material.dart 为主题的东西 以及我使用riverpod、stacked_services 和firebase 的真正动机。

这是颤振医生 -v 的结果:

[✓] Flutter (Channel master, 1.24.0-8.0.pre.98, on Mac OS X 10.15.7 19H2 darwin-x64, locale fr-FR)
    • Flutter version 1.24.0-8.0.pre.98 at /Users/Alex/development/flutter
    • Framework revision ef4ec09a06 (6 hours ago), 2020-11-05 08:02:13 -0800
    • Engine revision bf259226b2
    • Dart version 2.12.0 (build 2.12.0-21.0.dev)

[✓] android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at /Users/Alex/Library/Android/sdk
    • Platform android-30, build-tools 30.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✗] Xcode - develop for ios and macOS
    ✗ Xcode installation is incomplete; a full installation is necessary for iOS development.
      Download at: https://developer.apple.com/xcode/download/
      Or install Xcode via the App Store.
      Once installed, run:
        sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
        sudo xcodebuild -runFirstLaunch
    ✗ CocoaPods not installed.
        CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      To install see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.

[✓] Android Studio (version 4.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      ???? https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      ???? https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] Connected device (1 available)
    • sdk gphone x86 arm (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator)

! Doctor found issues in 1 category.

这是我在 pubspeck.yaml 中的依赖项

version: 1.0.0+1

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^1.0.0
  stacked_services:
  auto_route: 0.6.9
  hooks_riverpod: 0.12.1
  flutter_hooks:

  firebase_core: 0.5.1
  firebase_auth: 0.18.2

dev_dependencies:
  flutter_test:
    sdk: flutter
  build_runner:
  auto_route_generator:

有什么想法吗?我试图清理我的依赖项并重新安装。我还用颤振计数器应用程序启动了一个空白项目,它运行正常。

【问题讨论】:

尝试删除.packages文件、运行pub upgrade、删除pubspec.lock 【参考方案1】:

我今天升级 Flutter 后也遇到了这个问题。

我只能在从触发错误的文件中删除该方法参数后才能解决它。您必须在两个地方删除它。

在 .pub-cache/hosted/pub.dartlang.org/get-3.15.0/lib/get_navigation/src/extension_navigation.dart 中搜索

Theme.of(key.currentContext, shadowThemeOnly: true)

替换为

Theme.of(key.currentContext)

这可能是由于使用 get: ^3.15.0 依赖的stacked_services 依赖引起的

稍后编辑:这实际上不是最好的解决方案,因为有人克隆您的 repo 将无法编译项目,除非他们也进行此更改

所以最好升级导致这个错误的依赖,或者换成另一个;但只有在你运行颤振升级之后,或者尝试改变频道

【讨论】:

我删除了 Stacked 并使用 auto_route ExtendedNavigator 并且它可以工作。谢谢! 没问题。很高兴我能提供帮助。 谢谢@PhillauSofia【参考方案2】:

getx 在 16.1 中已经修复了这个问题。酒馆升级就行了

https://github.com/jonataslaw/getx/issues/762

【讨论】:

这应该是公认的答案,因为它不是黑客【参考方案3】:

你只需要删除

 ThemeData theme = Theme.of(key.currentContext, shadowThemeOnly: false);
    if (theme != null) 
      bottomSheet = new Theme(data: theme, child: bottomSheet);
    
    return bottomSheet;

形成您的 .pubcach 文件夹。

【讨论】:

以上是关于Flutter 无法运行,get_navigation & 主题错误的主要内容,如果未能解决你的问题,请参考以下文章

无法使用包运行 Flutter 项目

SDK 更新后 Flutter 无法运行

无法使用原生代码在 V2 Flutter 中截屏,它在 V1 Flutter 中运行良好

Flutter 应用程序在最新更新后无法运行

从 2.5.3 升级到 flutter 2.8.0 后无法运行 flutter run

Flutter_tts 无法在 iOS 上运行