better error handling for renderbox errors

pull/1428/head
ggurdin 1 year ago
parent 696bd0f129
commit f6bab92733
No known key found for this signature in database
GPG Key ID: A01CB41737CBB478

@ -105,17 +105,29 @@ class MessageOverlayController extends State<MessageSelectionOverlay>
/// This is a workaround to prevent that error /// This is a workaround to prevent that error
@override @override
void setState(VoidCallback fn) { void setState(VoidCallback fn) {
if (SchedulerBinding.instance.schedulerPhase == SchedulerPhase.idle || final phase = SchedulerBinding.instance.schedulerPhase;
SchedulerBinding.instance.schedulerPhase == if (mounted &&
SchedulerPhase.postFrameCallbacks && (phase == SchedulerPhase.idle ||
mounted) { phase == SchedulerPhase.postFrameCallbacks)) {
// It's safe to call setState immediately // It's safe to call setState immediately
super.setState(fn); try {
super.setState(fn);
} catch (e, s) {
ErrorHandler.logError(
e: "Error calling setState in MessageSelectionOverlay: $e",
s: s,
);
}
} else { } else {
// Defer the setState call to after the current frame // Defer the setState call to after the current frame
WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) { try {
super.setState(fn); if (mounted) super.setState(fn);
} catch (e, s) {
ErrorHandler.logError(
e: "Error calling setState in MessageSelectionOverlay after postframeCallback: $e",
s: s,
);
} }
}); });
} }
@ -404,6 +416,8 @@ class MessageOverlayController extends State<MessageSelectionOverlay>
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (messageSize == null) return const SizedBox.shrink();
final bool showDetails = (Matrix.of(context) final bool showDetails = (Matrix.of(context)
.store .store
.getBool(SettingKeys.displayChatDetailsColumn) ?? .getBool(SettingKeys.displayChatDetailsColumn) ??
@ -483,21 +497,25 @@ class MessageOverlayController extends State<MessageSelectionOverlay>
? FluffyThemes.columnWidth + FluffyThemes.navRailWidth ? FluffyThemes.columnWidth + FluffyThemes.navRailWidth
: 0; : 0;
final double? leftPadding = widget._pangeaMessageEvent.ownMessage final double? leftPadding =
? null (widget._pangeaMessageEvent.ownMessage || messageOffset == null)
: messageOffset!.dx - horizontalPadding - columnOffset; ? null
: messageOffset!.dx - horizontalPadding - columnOffset;
final double? rightPadding =
(widget._pangeaMessageEvent.ownMessage && screenWidth != null) final double? rightPadding = (widget._pangeaMessageEvent.ownMessage &&
? screenWidth! - screenWidth != null &&
messageOffset!.dx - messageOffset != null &&
messageSize!.width - messageSize != null)
horizontalPadding ? screenWidth! -
: null; messageOffset!.dx -
messageSize!.width -
final positionedOverlayMessage = horizontalPadding
(_overlayPositionAnimation == null || screenHeight == null) : null;
? Positioned(
final positionedOverlayMessage = (_overlayPositionAnimation == null)
? (screenHeight == null || messageSize == null || messageOffset == null)
? const SizedBox.shrink()
: Positioned(
left: leftPadding, left: leftPadding,
right: rightPadding, right: rightPadding,
bottom: screenHeight! - bottom: screenHeight! -
@ -506,17 +524,17 @@ class MessageOverlayController extends State<MessageSelectionOverlay>
belowMessageHeight, belowMessageHeight,
child: overlayMessage, child: overlayMessage,
) )
: AnimatedBuilder( : AnimatedBuilder(
animation: _overlayPositionAnimation!, animation: _overlayPositionAnimation!,
builder: (context, child) { builder: (context, child) {
return Positioned( return Positioned(
left: leftPadding, left: leftPadding,
right: rightPadding, right: rightPadding,
bottom: _overlayPositionAnimation!.value, bottom: _overlayPositionAnimation!.value,
child: overlayMessage, child: overlayMessage,
);
},
); );
},
);
return Padding( return Padding(
padding: EdgeInsets.only( padding: EdgeInsets.only(

Loading…
Cancel
Save