forked from eatvio/eatvio_app
Merge pull request 'Добавление таймера для подтверждения почты' (#643) from misha/eatvio_app:issue-642 into main
Reviewed-on: eatvio/eatvio_app#643
This commit is contained in:
@@ -1,5 +1,10 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:eatvio_app/core/locator_service.dart';
|
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/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_cubit.dart';
|
||||||
import 'package:eatvio_app/features/registration/presentation/bloc/verify_email_cubit/verify_email_state.dart';
|
import 'package:eatvio_app/features/registration/presentation/bloc/verify_email_cubit/verify_email_state.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@@ -18,11 +23,14 @@ class _VerifyEmailScreenState extends State<VerifyEmailScreen> {
|
|||||||
final List<TextEditingController> _controllers = List.generate(4, (_) => TextEditingController());
|
final List<TextEditingController> _controllers = List.generate(4, (_) => TextEditingController());
|
||||||
String email = '';
|
String email = '';
|
||||||
late final GoRouter goRouter;
|
late final GoRouter goRouter;
|
||||||
|
late Timer _timer;
|
||||||
|
int _secondsRemaining = 60;
|
||||||
|
bool _canSendAgain = false;
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
goRouter = GoRouter.of(context);
|
goRouter = GoRouter.of(context);
|
||||||
|
_startTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -36,6 +44,23 @@ class _VerifyEmailScreenState extends State<VerifyEmailScreen> {
|
|||||||
super.dispose();
|
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) {
|
void _checkAndSubmitCode(BuildContext context) {
|
||||||
final code = _controllers.map((c) => c.text).join();
|
final code = _controllers.map((c) => c.text).join();
|
||||||
if (code.length == 4) {
|
if (code.length == 4) {
|
||||||
@@ -74,18 +99,25 @@ class _VerifyEmailScreenState extends State<VerifyEmailScreen> {
|
|||||||
children: [
|
children: [
|
||||||
Text("Код отправлен на почту\n$email", textAlign: TextAlign.center),
|
Text("Код отправлен на почту\n$email", textAlign: TextAlign.center),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
Row(
|
Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: List.generate(4, (index) => _buildCodeField(context, index))),
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
const SizedBox(height: 40),
|
||||||
children: List.generate(4, (index) => _buildCodeField(context, index)),
|
CustomOutlinedButton(
|
||||||
),
|
text: 'Запросить код повторно',
|
||||||
const SizedBox(height: 20),
|
height: 52,
|
||||||
const Text("Запросить код повторно", style: TextStyle(color: Colors.grey)),
|
isDisabled: !_canSendAgain,
|
||||||
TextButton(
|
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700),
|
||||||
onPressed: () {
|
buttonStyle: ButtonStyle(
|
||||||
context.read<VerifyEmailCubit>().sendEmailCode();
|
side: const WidgetStatePropertyAll(BorderSide.none),
|
||||||
|
backgroundColor: WidgetStatePropertyAll(_canSendAgain ? appTheme.blueA400 : appTheme.gray),
|
||||||
|
),
|
||||||
|
onPressed: () async {
|
||||||
|
await context.read<VerifyEmailCubit>().sendEmailCode();
|
||||||
|
_startTimer();
|
||||||
},
|
},
|
||||||
child: const Text("Не приходит код?"),
|
|
||||||
),
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
if (!_canSendAgain)
|
||||||
|
Text("Зпросить код повторно можно через $_secondsRemaining с.", style: TextStyles.textSMedium.copyWith(color: appTheme.gray)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user