使用 Getx 小部件-Flutter 运行时显示错误
Posted
技术标签:
【中文标题】使用 Getx 小部件-Flutter 运行时显示错误【英文标题】:showing Error while running using Getx widget-Flutter 【发布时间】:2021-05-24 13:27:15 【问题描述】:此错误仅在我使用 get 包时发生。为了解决这个问题,我从 .pub-cache/hosted/pub.dartlang.org 目标中删除了 get 文件夹,然后再次导入它,但没有任何反应。
Launching lib\main.dart on sdk gphone x86 arm in debug mode...
Running Gradle task 'assembleDebug'...
/D:/Flutter/.pub-cache/hosted/pub.dartlang.org/get-3.25.4/lib/
get_navigation/src/root/get_cupertino_app.dart:121:9:
Error: Type 'RouteInformationProvider' not found.
final RouteInformationProvider routeInformationProvider;
^^^^^^^^^^^^^^^^^^^^^^^^
/D:/Flutter/.pub-cache/hosted/pub.dartlang.org/get-3.25.4/lib/
get_navigation/src/root/get_cupertino_app.dart:122:9: Error: Type
'RouteInformationParser' not found.
final RouteInformationParser<Object> routeInformationParser;
^^^^^^^^^^^^^^^^^^^^^^
/D:/Flutter/.pub-cache/hosted/pub.dartlang.org/get-3.25.4/lib/
get_navigation/src/root/get_cupertino_app.dart:122:9: Error:
Expected 0 type arguments.
final RouteInformationParser<Object> routeInformationParser;
^
/D:/Flutter/.pub-cache/hosted/pub.dartlang.org/get-3.25.4/lib/
get_navigation/src/root/get_cupertino_app.dart:123:9: Error: Type
'RouterDelegate' not found.
final RouterDelegate<Object> routerDelegate;
^^^^^^^^^^^^^^
/D:/Flutter/.pub-cache/hosted/pub.dartlang.org/get-3.25.4/lib/
get_navigation/src/root/get_cupertino_app.dart:123:9: Error:
Expected 0 type arguments.
final RouterDelegate<Object> routerDelegate;
^
/D:/Flutter/.pub-cache/hosted/pub.dartlang.org/get-3.25.4/lib/
get_navigation/src/root/get_material_app.dart:130:9: Error:
Expected 0 type arguments.
final RouteInformationParser<Object> routeInformationParser;
^^^^^^^^^^^^^^
/D:/Flutter/.pub-cache/hosted/pub.dartlang.org/get-3.25.4/lib/
get_navigation/src/root/get_material_app.dart:132:9: Error: '
BackButtonDispatcher' isn't a type.
final BackButtonDispatcher backButtonDispatcher;
^^^^^^^^^^^^^^^^^^^^
/D:/Flutter/.pub-cache/hosted/pub.dartlang.org/get-3.25.4/lib/
get_navigation/src/root/get_material_app.dart:245:25: Error:
Method not found: 'MaterialApp.router'.
? MaterialApp.router(
^^^^^^
FAILURE: Build failed with an exception.
* Where:
Script 'D:\Flutter\packages\flutter_tools\gradle\flutter.gradle'
line: 896
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'D:\Flutter\bin\flutter.bat'' 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 22s
Exception: Gradle task assembleDebug failed with exit code 1
我使用了很多其他包,但只有在使用get包时才会出现错误。
【问题讨论】:
升级 Flutter 后这个问题为我解决了。 【参考方案1】:打开你的安卓工作室终端
1 - 清理你的项目
flutter clean
2 - 将颤振通道更改为稳定
Flutter channels:
master
dev
beta
* stable
确保您在稳定的频道上
3 - 现在你需要升级flutter升级(在终端上)
flutter upgrade
输出
Flutter is already up to date on channel stable
Flutter 2.0.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision c5a4b4029c (2 days ago) • 2021-03-04 09:47:48 -0800
Engine • revision 40441def69
Tools • Dart 2.12.0
4 - 再次清理
flutter clean
如果你在颤振 2 上,那么一切都很好:)
【讨论】:
以上是关于使用 Getx 小部件-Flutter 运行时显示错误的主要内容,如果未能解决你的问题,请参考以下文章