Flutter编译报错:'nthrow'非类型及垂直视口无界问题求助
Flutter切换设备后编译报错:'nthrow' isn't a type
问题核心
编译错误指向Flutter框架源码文件debug.dart第328行的nthrow,这是拼写错误,正确应为throw。
报错详情
Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source! Launching lib\main.dart on SM A037F in debug mode... main.dart:1 Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source! /E:/AppData/new/flutter/packages/flutter/lib/src/rendering/debug.dart:328:13: Error: 'nthrow' isn't a type. nthrow FlutterError.fromParts(<DiagnosticsNode>[ ^^^^^^ /E:/AppData/new/flutter/packages/flutter/lib/src/rendering/debug.dart:328:20: Error: Expected ';' after this. nthrow FlutterError.fromParts(<DiagnosticsNode>[ ^^^^^^^^^^^^ /E:/AppData/new/flutter/packages/flutter/lib/src/rendering/debug.dart:328:32: Error: Expected an identifier, but got '.'. Try inserting an identifier before '.'. nthrow FlutterError.fromParts(<DiagnosticsNode>[ ^ Target kernel_snapshot failed: Exception 2 FAILURE: Build failed with an exception. * Where: Script 'E:\AppData\new\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1201 * What went wrong: Execution failed for task ':app:compileFlutterBuildDebug'. > Process 'command 'E:\AppData\new\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 14s Exception: Gradle task assembleDebug failed with exit code 1 Exited (sigterm)
出错代码片段
if (!constraints.hasBoundedHeight) { nthrow FlutterError.fromParts(<DiagnosticsNode>[ ErrorSummary('Vertical viewport was given unbounded height.'), ErrorDescription( 'Viewports expand in the scrolling direction to fill their container. ' 'In this case, a vertical viewport was given an unlimited amount of ' 'vertical space in which to expand. This situation typically happens ' 'when a scrollable widget is nested inside another scrollable widget.', ), ErrorHint( 'If this widget is always nested in a scrollable widget there ' 'is no need to use a viewport because there will always be enough ' 'vertical space for the children. In this case, consider using a ' 'Column or Wrap instead. Otherwise, consider using a ' 'CustomScrollView to concatenate arbitrary slivers into a ' 'single scrollable.', ), ]); }
当前环境信息
- Flutter版本:
Flutter 3.10.2 • channel stable • https://github.com/flutter/flutter.git Framework • revision 9cd3d0d9ff (12 days ago) • 2023-05-23 20:57:28 -0700 Engine • revision 90fa3ae28f Tools • Dart 3.0.2 • DevTools 2.23.1
flutter doctor结果:
Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source! Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, 3.10.2, on Microsoft Windows [Version 10.0.19045.2965], locale en-KE) [√] Windows Version (Installed version of Windows is version 10 or higher) [√] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1) [√] Chrome - develop for the web [√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.6.2) [√] Android Studio (version 2021.2) [√] VS Code (version 1.78.2) [√] Connected device (4 available) [√] Network resources • No issues found!
解决方案
方案1:手动修正源码拼写错误
- 定位到文件:
E:/AppData/new/flutter/packages/flutter/lib/src/rendering/debug.dart - 找到第328行,将
nthrow替换为throw - 保存文件后,执行以下命令重新编译:
flutter clean flutter run
方案2:重新安装Flutter SDK(若不想手动修改源码)
- 备份项目的
pubspec.yaml文件 - 删除现有Flutter SDK目录(
E:/AppData/new/flutter) - 下载对应版本(3.10.2)的Flutter SDK并解压到原目录
- 配置好环境变量后,进入项目目录执行:
flutter pub get flutter run
内容的提问来源于stack exchange,提问作者Collins Njoka
相关产品推荐
相关产品推荐

