diff --git a/lib/core/auth_gate.dart b/lib/core/auth_gate.dart index 94e63f8..7b944e3 100644 --- a/lib/core/auth_gate.dart +++ b/lib/core/auth_gate.dart @@ -156,23 +156,24 @@ class _AuthGateState extends State with WidgetsBindingObserver { @override Widget build(BuildContext context) { - // Not yet initialized - show nothing (brief flash) - if (!_isInitialized) { - return const SizedBox.shrink(); - } - - // Not locked - show the app - if (!_isLocked) { - return GestureDetector( - behavior: HitTestBehavior.translucent, - onTap: _recordUserActivity, - onPanDown: (_) => _recordUserActivity(), - child: widget.child, - ); - } - - // Locked - show auth screen - return _buildLockScreen(); + // Use Stack to keep widget tree stable during transitions + return Stack( + children: [ + // Always keep child in tree (but behind lock screen when locked) + Offstage( + offstage: _isLocked, + child: GestureDetector( + behavior: HitTestBehavior.translucent, + onTap: _recordUserActivity, + onPanDown: (_) => _recordUserActivity(), + child: widget.child, + ), + ), + // Lock screen overlay + if (_isLocked || !_isInitialized) + _buildLockScreen(), + ], + ); } Widget _buildLockScreen() { diff --git a/lib/main.dart b/lib/main.dart index 186e6e3..c28c7a7 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -115,25 +115,17 @@ class MainScaffold extends StatefulWidget { class MainScaffoldState extends State { int _currentIndex = 0; final GlobalKey _webViewKey = GlobalKey(); - - final List _screens = []; - - @override - void initState() { - super.initState(); - _screens.addAll([ - WebViewScreen(key: _webViewKey), - const InputScreen(), - const SettingsScreen(), - ]); - } @override Widget build(BuildContext context) { return Scaffold( body: IndexedStack( index: _currentIndex, - children: _screens, + children: [ + WebViewScreen(key: _webViewKey), + const InputScreen(), + const SettingsScreen(), + ], ), bottomNavigationBar: NavigationBar( selectedIndex: _currentIndex,