fix for resend, cooldown and a few small fixes
This commit is contained in:
@@ -3,6 +3,8 @@ import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pweb/providers/two_factor.dart';
|
||||
import 'package:pweb/utils/cooldown_format.dart';
|
||||
import 'package:pweb/widgets/resend_link.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
@@ -12,46 +14,20 @@ class ResendCodeButton extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final localizations = AppLocalizations.of(context)!;
|
||||
final provider = context.watch<TwoFactorProvider>();
|
||||
final isDisabled = provider.isCooldownActive || provider.isResending;
|
||||
|
||||
final label = provider.isCooldownActive
|
||||
? '${localizations.twoFactorResend} (${_formatCooldown(provider.cooldownRemainingSeconds)})'
|
||||
? '${localizations.twoFactorResend} (${formatCooldownSeconds(provider.cooldownRemainingSeconds)})'
|
||||
: localizations.twoFactorResend;
|
||||
|
||||
return TextButton(
|
||||
onPressed: isDisabled ? null : () => provider.resendCode(),
|
||||
style: TextButton.styleFrom(
|
||||
padding: EdgeInsets.zero,
|
||||
minimumSize: const Size(0, 0),
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
alignment: Alignment.centerLeft,
|
||||
foregroundColor: theme.colorScheme.primary,
|
||||
textStyle: theme.textTheme.bodyMedium?.copyWith(
|
||||
decoration: TextDecoration.underline,
|
||||
),
|
||||
),
|
||||
child: provider.isResending
|
||||
? SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
)
|
||||
: Text(label),
|
||||
return ResendLink(
|
||||
label: label,
|
||||
onPressed: provider.resendCode,
|
||||
isDisabled: isDisabled,
|
||||
isLoading: provider.isResending,
|
||||
);
|
||||
}
|
||||
|
||||
String _formatCooldown(int seconds) {
|
||||
final minutes = seconds ~/ 60;
|
||||
final remainingSeconds = seconds % 60;
|
||||
if (minutes > 0) {
|
||||
return '$minutes:${remainingSeconds.toString().padLeft(2, '0')}';
|
||||
}
|
||||
return remainingSeconds.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user