Fix: Widget tree stability - move screen creation to build method
This commit is contained in:
parent
079cbb07cf
commit
0c8848af1b
|
|
@ -156,23 +156,24 @@ class _AuthGateState extends State<AuthGate> 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() {
|
||||
|
|
|
|||
|
|
@ -115,25 +115,17 @@ class MainScaffold extends StatefulWidget {
|
|||
class MainScaffoldState extends State<MainScaffold> {
|
||||
int _currentIndex = 0;
|
||||
final GlobalKey<WebViewScreenState> _webViewKey = GlobalKey();
|
||||
|
||||
final List<Widget> _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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue