Skip to content

Commit

Permalink
fix: Let's try to fix a crash with a null variable in the `CameraScan…
Browse files Browse the repository at this point in the history
…nerPageState` (#4713)

* Let's try to fix a crash in Sentry

* A call to `setState` was missing
  • Loading branch information
g123k committed Oct 25, 2023
1 parent 9a1ba90 commit f87e257
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions packages/smooth_app/lib/pages/scan/camera_scan_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,32 @@ class CameraScannerPageState extends State<CameraScannerPage>
_userPreferences = context.watch<UserPreferences>();
}

_detectHeaderHeight();
}

/// In some cases, the size may be null
/// (Mainly when the app is launched for the first time AND in release mode)
void _detectHeaderHeight([int retries = 0]) {
// Let's try during 5 frames (should be enough, as 2 or 3 seems to be an average)
if (retries > 5) {
return;
}

WidgetsBinding.instance.addPostFrameCallback((_) {
setState(() {
try {
_headerHeight =
(_headerKey.currentContext?.findRenderObject() as RenderBox?)
?.size
.height;
});
} catch (_) {
_headerHeight = null;
}

if (_headerHeight == null) {
_detectHeaderHeight(retries + 1);
} else {
setState(() {});
}
});
}

Expand Down

0 comments on commit f87e257

Please sign in to comment.