diff --git a/lib/features/registration/presentation/pages/verify_email_screen.dart b/lib/features/registration/presentation/pages/verify_email_screen.dart index ed4ea11f..f50d4960 100644 --- a/lib/features/registration/presentation/pages/verify_email_screen.dart +++ b/lib/features/registration/presentation/pages/verify_email_screen.dart @@ -1,5 +1,10 @@ +import 'dart:async'; + import 'package:eatvio_app/core/locator_service.dart'; +import 'package:eatvio_app/core/theme/custom_text_style.dart'; +import 'package:eatvio_app/core/theme/theme_helper.dart'; import 'package:eatvio_app/core/utils/toasts.dart'; +import 'package:eatvio_app/core/widgets/custom_outlined_button.dart'; import 'package:eatvio_app/features/registration/presentation/bloc/verify_email_cubit/verify_email_cubit.dart'; import 'package:eatvio_app/features/registration/presentation/bloc/verify_email_cubit/verify_email_state.dart'; import 'package:flutter/material.dart'; @@ -18,11 +23,14 @@ class _VerifyEmailScreenState extends State { final List _controllers = List.generate(4, (_) => TextEditingController()); String email = ''; late final GoRouter goRouter; - + late Timer _timer; + int _secondsRemaining = 60; + bool _canSendAgain = false; @override void initState() { super.initState(); - goRouter = GoRouter.of(context); + goRouter = GoRouter.of(context); + _startTimer(); } @override @@ -36,6 +44,23 @@ class _VerifyEmailScreenState extends State { super.dispose(); } + void _startTimer() { + setState(() { + _canSendAgain = false; + _secondsRemaining = 60; + }); + _timer = Timer.periodic(const Duration(seconds: 1), (timer) { + setState(() { + if (_secondsRemaining > 0) { + _secondsRemaining--; + } else { + _canSendAgain = true; + _timer.cancel(); + } + }); + }); + } + void _checkAndSubmitCode(BuildContext context) { final code = _controllers.map((c) => c.text).join(); if (code.length == 4) { @@ -74,18 +99,25 @@ class _VerifyEmailScreenState extends State { children: [ Text("Код отправлен на почту\n$email", textAlign: TextAlign.center), const SizedBox(height: 20), - Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: List.generate(4, (index) => _buildCodeField(context, index)), - ), - const SizedBox(height: 20), - const Text("Запросить код повторно", style: TextStyle(color: Colors.grey)), - TextButton( - onPressed: () { - context.read().sendEmailCode(); + Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: List.generate(4, (index) => _buildCodeField(context, index))), + const SizedBox(height: 40), + CustomOutlinedButton( + text: 'Запросить код повторно', + height: 52, + isDisabled: !_canSendAgain, + buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700), + buttonStyle: ButtonStyle( + side: const WidgetStatePropertyAll(BorderSide.none), + backgroundColor: WidgetStatePropertyAll(_canSendAgain ? appTheme.blueA400 : appTheme.gray), + ), + onPressed: () async { + await context.read().sendEmailCode(); + _startTimer(); }, - child: const Text("Не приходит код?"), ), + const SizedBox(height: 8), + if (!_canSendAgain) + Text("Зпросить код повторно можно через $_secondsRemaining с.", style: TextStyles.textSMedium.copyWith(color: appTheme.gray)), ], ), ),