diff --git a/lib/frontend/screens/auth/code_confirmation_screen.dart b/lib/frontend/screens/auth/code_confirmation_screen.dart index 3840751..512a938 100644 --- a/lib/frontend/screens/auth/code_confirmation_screen.dart +++ b/lib/frontend/screens/auth/code_confirmation_screen.dart @@ -34,13 +34,14 @@ class _CodeConfirmationScreenState extends State late AnimationController _shakeController; late Animation _shakeAnimation; + bool _keyboardScheduled = false; + Animation? _routeAnimation; + AnimationStatusListener? _routeAnimationListener; + @override void initState() { super.initState(); _startTimer(); - WidgetsBinding.instance.addPostFrameCallback((_) { - _focusNode.requestFocus(); - }); _shakeController = AnimationController( vsync: this, @@ -56,8 +57,17 @@ class _CodeConfirmationScreenState extends State ]).animate(CurvedAnimation(parent: _shakeController, curve: Curves.linear)); } + @override + void didChangeDependencies() { + super.didChangeDependencies(); + _scheduleKeyboardOpen(); + } + @override void dispose() { + if (_routeAnimationListener != null) { + _routeAnimation?.removeStatusListener(_routeAnimationListener!); + } _timer?.cancel(); _errorTimer?.cancel(); _shakeController.dispose(); @@ -66,6 +76,36 @@ class _CodeConfirmationScreenState extends State super.dispose(); } + void _scheduleKeyboardOpen() { + if (_keyboardScheduled) return; + _keyboardScheduled = true; + + final animation = ModalRoute.of(context)?.animation; + if (animation == null || animation.status == AnimationStatus.completed) { + WidgetsBinding.instance.addPostFrameCallback((_) { + if (mounted) _openKeyboard(); + }); + return; + } + + _routeAnimation = animation; + _routeAnimationListener = (status) { + if (status == AnimationStatus.completed) { + animation.removeStatusListener(_routeAnimationListener!); + _routeAnimationListener = null; + if (mounted) _openKeyboard(); + } + }; + animation.addStatusListener(_routeAnimationListener!); + } + + void _openKeyboard() { + if (!_focusNode.hasFocus) { + _focusNode.requestFocus(); + } + SystemChannels.textInput.invokeMethod('TextInput.show'); + } + void _startTimer() { _timer?.cancel(); _timerSeconds = 30; @@ -215,7 +255,7 @@ class _CodeConfirmationScreenState extends State ), ), GestureDetector( - onTap: () => _focusNode.requestFocus(), + onTap: _openKeyboard, child: FittedBox( child: Row( children: List.generate(6, (index) {