【发布时间】:2023-02-01 20:49:03
【问题描述】:
在 windows 上调试时抛出异常,stacktrace:
ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Scaffold.geometryOf() must only be accessed during the paint phase.
The ScaffoldGeometry is only available during the paint phase, because its value is computed during the animation and layout phases prior to painting.
#0 _ScaffoldGeometryNotifier.value.<anonymous closure> (package:flutter/src/material/scaffold.dart:835:9)
#1 _ScaffoldGeometryNotifier.value (package:flutter/src/material/scaffold.dart:842:6)
#2 _BottomAppBarClipper.getClip (package:flutter/src/material/bottom_app_bar.dart:238:35)
堆栈跟踪暗示从我的小部件中的 BottomAppBar 获取几何值。当我在屏幕上移动鼠标时,此错误之后是 mouse_tracker 的许多错误消息:
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: 'package:flutter/src/rendering/mouse_tracker.dart': Failed assertion: line 195 pos 12: '!_debugDuringDeviceUpdate': is not true.
#0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
#1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
#2 MouseTracker._deviceUpdatePhase (package:flutter/src/rendering/mouse_tracker.dart:195:12)
此后屏幕上的任何内容都不可点击。
该错误仅在按下 FloatingActionButton 后发生,如果按下页面上的后退按钮则不会发生。 FAB 的 onPressed 是:
void onOkPressed() {
Navigator.of(context).pop();
}
我该如何解决这个错误?
【问题讨论】:
标签: flutter floating-action-button flutter-windows