fix: автооткрытие клавиатуры на экране кода

This commit is contained in:
klockky
2026-04-21 18:59:35 +03:00
parent 4ebfb3353f
commit 602c924503
@@ -34,13 +34,14 @@ class _CodeConfirmationScreenState extends State<CodeConfirmationScreen>
late AnimationController _shakeController;
late Animation<double> _shakeAnimation;
bool _keyboardScheduled = false;
Animation<double>? _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<CodeConfirmationScreen>
]).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<CodeConfirmationScreen>
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<void>('TextInput.show');
}
void _startTimer() {
_timer?.cancel();
_timerSeconds = 30;
@@ -215,7 +255,7 @@ class _CodeConfirmationScreenState extends State<CodeConfirmationScreen>
),
),
GestureDetector(
onTap: () => _focusNode.requestFocus(),
onTap: _openKeyboard,
child: FittedBox(
child: Row(
children: List.generate(6, (index) {