我正在编写一个Flutter应用程序,但是当我想在Android Emulator(Ctrl + F5)上对其进行测试时,出现了无法修复的错误。这是其中的一部分:
I/flutter (13782): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (13782): The following assertion was thrown during performResize():
I/flutter (13782): Vertical viewport was given unbounded height.
I/flutter (13782): Viewports expand in the scrolling direction to fill their container. In this case, a vertical
I/flutter (13782): viewport was given an unlimited amount of vertical space in which to expand. This situation
I/flutter (13782): typically happens when a scrollable widget is nested inside another scrollable widget.
I/flutter (13782): If this widget is always nested in a scrollable widget there is no need to use a viewport because
I/flutter (13782): there will always be enough vertical space for the children. In this case, consider using a Column
I/flutter (13782): instead. Otherwise, consider using the "shrinkWrap" property (or a ShrinkWrappingViewport) to size
I/flutter (13782): the height of the viewport to the sum of the heights of its children.
I/flutter (13782):
I/flutter (13782): The relevant error-causing widget was:
I/flutter (13782): ListView (file:///D:/flutterProjects/test_project/test_project/lib/screens/all_obj_screen.dart:19:18)
如您在最后一行所看到的,它表明错误的原因是ListView
中的D:/flutterProjects/test_project/test_project/lib/screens/all_obj_screen.dart
。问题在于该文件中没有ListView
(目前,但我以前有),而且该路径甚至不存在!
如果有帮助,则为all_obj_screen.dart
文件:
class AllObjScreen extends StatefulWidget {
@override
_AllObjScreenState createState() => _AllObjScreenState();
}
class _AllObjScreenState extends State<AllObjScreen> {
@override
Widget build(BuildContext context) {
final objects = Provider.of<Objs>(context);
return Center(
child: Text(
'${objects.items.length}',
style: TextStyle(
color: Colors.white,
fontSize: 25,
),
),
);
}
}
因此,我认为问题不是我的代码,而是有关Visual Studio Code的问题。如何解决此问题?
编辑: 我试图在Visual Studio Code和Android Studio上都运行该应用程序,但问题是相同的。 我还尝试过重新安装IDE并使其颤抖,但是一点都不运气。
答案 0 :(得分:3)
尝试:
flutter logs -c
(要清除日志,请在项目目录中运行)
清洁后,按CTRL + C并回答Y。希望它会有所帮助。谢谢
答案 1 :(得分:2)
从1.12版开始,我遇到了同样的问题。 重新启动设备会清除日志,但我希望Flutter在将来的版本中会更正此问题。 这只是使用Android设备发生的。在iOS中可以正常工作。
答案 2 :(得分:1)
简短答案::删除该设备(模拟器)并创建另一个新设备。
长话短说:
我有同样的问题!该代码是完美的,突然之间我没有任何机会基于事件触发大量错误提示!
我尝试了flutter clean
,但并没有解决问题,并尝试了所有事件,我删除了处理错误触发事件的所有代码,但我没有运气,一次又一次地出现错误,而没有代码生成它们!!。
直到我考虑尝试使用另一个模拟器,魔术才发生!没有错误!
答案 3 :(得分:1)
您可以看到它:https://github.com/flutter/flutter/issues/46815。 在flutter版本1.12.13 + hotfix8中已解决此问题。