import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; import '../../../providers/auth_provider.dart'; import '../../../core/theme/app_theme.dart'; class TwoFactorScreen extends ConsumerStatefulWidget { const TwoFactorScreen({super.key}); @override ConsumerState createState() => _TwoFactorScreenState(); } class _TwoFactorScreenState extends ConsumerState { final _codeController = TextEditingController(); @override void dispose() { _codeController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { final authState = ref.watch(authProvider); final authNotifier = ref.read(authProvider.notifier); ref.listen(authProvider, (_, state) { if (state.status == AuthStatus.authenticated) { context.go('/'); } }); return Scaffold( appBar: AppBar(title: const Text('Двухфакторная аутентификация')), body: Padding( padding: const EdgeInsets.all(24), child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ const SizedBox(height: 48), const Icon( Icons.security, size: 64, color: VoIdeaColors.primary, ), const SizedBox(height: 24), Text( 'Введите код из приложения аутентификации', textAlign: TextAlign.center, style: Theme.of(context).textTheme.bodyLarge, ), const SizedBox(height: 32), TextField( controller: _codeController, keyboardType: TextInputType.number, textAlign: TextAlign.center, decoration: InputDecoration( hintText: '000000', counterText: '', helperText: '6-значный код', ), maxLength: 6, style: const TextStyle(fontSize: 32, letterSpacing: 8), ), const SizedBox(height: 32), if (authState.error != null) Padding( padding: const EdgeInsets.only(bottom: 16), child: Text( authState.error!, style: const TextStyle(color: VoIdeaColors.error), textAlign: TextAlign.center, ), ), ElevatedButton( onPressed: authState.status == AuthStatus.loading ? null : () { if (_codeController.text.length == 6) { authNotifier.verifyTwoFactor(_codeController.text); } }, child: authState.status == AuthStatus.loading ? const SizedBox( height: 20, width: 20, child: CircularProgressIndicator( strokeWidth: 2, color: Colors.white, ), ) : const Text('Подтвердить'), ), const SizedBox(height: 16), TextButton( onPressed: () { authNotifier.logout(); context.go('/auth/login'); }, child: const Text('Назад ко входу'), ), ], ), ), ); } }