Flutter项目运行报错:FlutterView未定义viewConfiguration
Flutter项目运行指定分支编译错误求助
我的Flutter项目仓库地址:https://github.com/Sanmitha-Sadhishkumar/AU_Hitch_Handler,运行Rahulraj分支代码时出现如下编译错误:
/C:/Users/Sanmitha/AppData/Local/Pub/Cache/hosted/pub.dev/flutter_screenutil-5.6.1/lib/src/screen_util.dart:64:16: Error: The getter 'viewConfiguration' isn't defined for the class 'FlutterView'. - 'FlutterView' is from 'dart:ui'. Try correcting the name to the name of an existing getter, or defining a getter or field named 'viewConfiguration'. if (window.viewConfiguration.geometry.isEmpty) { ^^^^^^^^^^^^^^^^^ Target kernel_snapshot failed: Exception FAILURE: Build failed with an exception. * Where: Script 'C:\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1153 * What went wrong: Execution failed for task ':app:compileFlutterBuildDebug'. > Process 'command 'C:\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 6s Exception: Gradle task assembleDebug failed with exit code 1
问题原因
错误源于使用的flutter_screenutil-5.6.1版本与当前Flutter SDK不兼容——Flutter SDK在后续版本中移除了FlutterView的viewConfiguration属性,旧版依赖包调用该属性时触发报错。
解决步骤
- 升级
flutter_screenutil依赖:打开项目的pubspec.yaml文件,将flutter_screenutil的版本更新至最新兼容版(如^5.9.0或更高),执行flutter pub get更新依赖 - 升级Flutter SDK:在终端执行
flutter upgrade命令,将本地Flutter SDK升级到最新稳定版 - 清理项目缓存:执行
flutter clean清除旧编译缓存,再重新执行flutter pub get和编译命令
恳请各位帮忙调试该问题,谢谢!
内容的提问来源于stack exchange,提问作者Hello World
相关产品推荐
相关产品推荐

