Skip to content

Commit fdc31c3

Browse files
[SuperEditor] - Keyboard safe area: Catch possible local to global exception (#2601)
1 parent 26db51b commit fdc31c3

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

super_editor/lib/src/infrastructure/keyboard_panel_scaffold.dart

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,22 @@ class _KeyboardScaffoldSafeAreaState extends State<KeyboardScaffoldSafeArea> {
11101110
var bottomInsets = keyboardSafeArea.bottomInsets;
11111111
if (_myBoxKey.currentContext != null && _myBoxKey.currentContext!.findRenderObject() != null) {
11121112
final myBox = _myBoxKey.currentContext!.findRenderObject() as RenderBox;
1113-
final myGlobalBottom = myBox.localToGlobal(Offset(0, myBox.size.height)).dy;
1113+
1114+
late final double myGlobalBottom;
1115+
try {
1116+
myGlobalBottom = myBox.localToGlobal(Offset(0, myBox.size.height)).dy;
1117+
} catch (exception) {
1118+
// It was found in a client app that there can be situations where at
1119+
// this moment some render object in the ancestor chain isn't yet laid
1120+
// out. This results in an exception. The best we can do is return zero.
1121+
if (isLogActive(keyboardPanelLog)) {
1122+
keyboardPanelLog.warning(
1123+
"KeyboardScaffoldSafeArea (${widget.debugLabel}) - Tried to measure our global bottom offset on the screen but caused an exception, likely due to an ancestor not yet being laid out.\nException: $exception\nStacktrace:\n${StackTrace.current}",
1124+
);
1125+
}
1126+
return 0;
1127+
}
1128+
11141129
if (myGlobalBottom.isNaN) {
11151130
// We've found in a client app that under some unknown circumstances we get NaN
11161131
// from localToGlobal(). We're not sure why. In that case, log a warning and return zero.

0 commit comments

Comments
 (0)