From 2c7b18f410e75d8f73dcfd060dafadf0da5a0af6 Mon Sep 17 00:00:00 2001 From: Jonas Bark Date: Wed, 19 Aug 2026 22:13:29 +0200 Subject: [PATCH] fix(paywall): "Go Pro" from the trainer picker opens instead of crashing The onboarding trainer picker passed the State's own context into connectTrainerFromPicker. Its trial gate opens the Go Pro dialog, whose purchase action opens the paywall drawer -- and that context sits above the Scaffold's DrawerOverlay, so openDrawer's `parentLayer!` threw. In release the user saw only a "Null check operator used on a null value" toast and the paywall never appeared, which on an expired trial leaves no way forward at all. Pass _sheetContext, which lives below the Scaffold. _showPaywall also stops depending on callers getting that right: with no DrawerOverlay ancestor it now falls back to showDialog, which only needs a Navigator. The paywall already constrains and scrolls itself, so it renders correctly either way. The paywall is the last thing that should break when a caller passes the wrong context. Symbolized from a support bundle (chat 197d1f1a, Windows 6.4.3 patch 13): four identical traces seconds apart, each on the Go Pro tap. Co-Authored-By: Claude Opus 5 (1M context) --- lib/pages/onboarding/onboarding_page.dart | 6 +++++- lib/utils/iap/iap_manager.dart | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/pages/onboarding/onboarding_page.dart b/lib/pages/onboarding/onboarding_page.dart index 0160f8c6..cbd8866e 100644 --- a/lib/pages/onboarding/onboarding_page.dart +++ b/lib/pages/onboarding/onboarding_page.dart @@ -579,7 +579,11 @@ class _OnboardingPageState extends State { /// of ConnectionCard._onSelect (proxy_device_details/connection_card.dart); /// the details page stays reachable from the home screen for mode changes. Future _onPickTrainer(ProxyDevice device) async { - await connectTrainerFromPicker(context, device); + // _sheetContext, not context: the trial gate in connectTrainerFromPicker + // opens the Go Pro dialog, whose purchase action opens the paywall drawer. + // The State's own context sits above the Scaffold's DrawerOverlay, so that + // drawer died on a null check — see the note on [_sheetContext]. + await connectTrainerFromPicker(_sheetContext, device); if (mounted) setState(() {}); } diff --git a/lib/utils/iap/iap_manager.dart b/lib/utils/iap/iap_manager.dart index 5b3b1e4b..13afa154 100644 --- a/lib/utils/iap/iap_manager.dart +++ b/lib/utils/iap/iap_manager.dart @@ -341,6 +341,20 @@ class IAPManager { } Future _showPaywall(BuildContext context, bool subscription) async { + // openDrawer needs a DrawerOverlay ancestor (Scaffold creates one) and does + // `parentLayer!` in release, so a caller that hands us a context from above + // its own Scaffold turns "Go Pro" into a bare "Null check operator used on + // a null value" toast and the paywall never opens. Callers should pass a + // context below the Scaffold, but the paywall is the last thing that should + // break when one doesn't — fall back to a dialog, which only needs a + // Navigator. Paywall already constrains and scrolls itself. + if (DrawerOverlay.maybeFind(context) == null) { + await showDialog( + context: context, + builder: (c) => Paywall(defaultToFullVersion: !subscription), + ); + return; + } openDrawer( context: context, // The paywall scrolls, which swallows the drawer's own swipe-to-close —