LCOV - code coverage report
Current view: top level - lib/screens/auth - forgot_password_screen.dart Coverage Total Hit
Test: lcov.info Lines: 2.3 % 44 1
Test Date: 2025-08-12 03:21:51 Functions: - 0 0

            Line data    Source code
       1              : import 'package:flutter/material.dart';
       2              : import 'package:provider/provider.dart';
       3              : import '../../services/auth_service.dart';
       4              : 
       5              : class ForgotPasswordScreen extends StatefulWidget {
       6           24 :   const ForgotPasswordScreen({super.key});
       7              : 
       8            0 :   @override
       9            0 :   State<ForgotPasswordScreen> createState() => _ForgotPasswordScreenState();
      10              : }
      11              : 
      12              : class _ForgotPasswordScreenState extends State<ForgotPasswordScreen> {
      13              :   final _formKey = GlobalKey<FormState>();
      14              :   final _emailController = TextEditingController();
      15              :   bool _isSubmitting = false;
      16              :   bool _emailSent = false;
      17              : 
      18            0 :   @override
      19              :   void dispose() {
      20            0 :     _emailController.dispose();
      21            0 :     super.dispose();
      22              :   }
      23              : 
      24              :   // 비밀번호 재설정 이메일 전송 함수
      25            0 :   Future<void> _resetPassword() async {
      26            0 :     if (_formKey.currentState!.validate()) {
      27            0 :       setState(() {
      28            0 :         _isSubmitting = true;
      29              :       });
      30              : 
      31            0 :       final authService = Provider.of<AuthService>(context, listen: false);
      32            0 :       final success = await authService.sendPasswordResetEmail(
      33            0 :         _emailController.text.trim(),
      34              :       );
      35              : 
      36            0 :       setState(() {
      37            0 :         _isSubmitting = false;
      38            0 :         _emailSent = success;
      39              :       });
      40              : 
      41            0 :       if (success && mounted) {
      42            0 :         ScaffoldMessenger.of(context).showSnackBar(
      43              :           const SnackBar(
      44              :             content: Text('비밀번호 재설정 이메일이 전송되었습니다. 이메일을 확인해주세요.'),
      45              :             backgroundColor: Colors.green,
      46              :           ),
      47              :         );
      48            0 :       } else if (mounted) {
      49            0 :         ScaffoldMessenger.of(context).showSnackBar(
      50              :           const SnackBar(
      51              :             content: Text('비밀번호 재설정 이메일 전송에 실패했습니다. 이메일 주소를 확인해주세요.'),
      52              :             backgroundColor: Colors.red,
      53              :           ),
      54              :         );
      55              :       }
      56              :     }
      57              :   }
      58              : 
      59            0 :   @override
      60              :   Widget build(BuildContext context) {
      61            0 :     return Scaffold(
      62            0 :       appBar: AppBar(
      63              :         title: const Text('비밀번호 찾기'),
      64              :       ),
      65            0 :       body: SafeArea(
      66            0 :         child: Center(
      67            0 :           child: SingleChildScrollView(
      68              :             padding: const EdgeInsets.all(24.0),
      69            0 :             child: Form(
      70            0 :               key: _formKey,
      71            0 :               child: Column(
      72              :                 mainAxisAlignment: MainAxisAlignment.center,
      73              :                 crossAxisAlignment: CrossAxisAlignment.stretch,
      74            0 :                 children: [
      75              :                   const Icon(
      76              :                     Icons.lock_reset,
      77              :                     size: 80,
      78              :                     color: Colors.blue,
      79              :                   ),
      80              :                   const SizedBox(height: 24),
      81              :                   
      82              :                   const Text(
      83              :                     '비밀번호를 잊으셨나요?',
      84              :                     textAlign: TextAlign.center,
      85              :                     style: TextStyle(
      86              :                       fontSize: 24,
      87              :                       fontWeight: FontWeight.bold,
      88              :                     ),
      89              :                   ),
      90              :                   const SizedBox(height: 16),
      91              :                   
      92              :                   const Text(
      93              :                     '가입하신 이메일 주소를 입력하시면 비밀번호 재설정 링크를 보내드립니다.',
      94              :                     textAlign: TextAlign.center,
      95              :                     style: TextStyle(
      96              :                       fontSize: 16,
      97              :                       color: Colors.grey,
      98              :                     ),
      99              :                   ),
     100              :                   const SizedBox(height: 32),
     101              : 
     102              :                   // 이메일 입력 필드
     103            0 :                   TextFormField(
     104            0 :                     controller: _emailController,
     105              :                     keyboardType: TextInputType.emailAddress,
     106              :                     decoration: const InputDecoration(
     107              :                       labelText: '이메일',
     108              :                       prefixIcon: Icon(Icons.email),
     109              :                       border: OutlineInputBorder(),
     110              :                     ),
     111            0 :                     validator: (value) {
     112            0 :                       if (value == null || value.isEmpty) {
     113              :                         return '이메일을 입력해주세요';
     114              :                       }
     115            0 :                       if (!RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$').hasMatch(value)) {
     116              :                         return '유효한 이메일 주소를 입력해주세요';
     117              :                       }
     118              :                       return null;
     119              :                     },
     120              :                   ),
     121              :                   const SizedBox(height: 24),
     122              : 
     123              :                   // 비밀번호 재설정 이메일 전송 버튼
     124            0 :                   ElevatedButton(
     125            0 :                     onPressed: _isSubmitting ? null : _resetPassword,
     126            0 :                     style: ElevatedButton.styleFrom(
     127              :                       padding: const EdgeInsets.symmetric(vertical: 16),
     128              :                       backgroundColor: Colors.blue,
     129              :                       foregroundColor: Colors.white,
     130              :                     ),
     131            0 :                     child: _isSubmitting
     132              :                         ? const SizedBox(
     133              :                             width: 20,
     134              :                             height: 20,
     135              :                             child: CircularProgressIndicator(
     136              :                               strokeWidth: 2,
     137              :                               color: Colors.white,
     138              :                             ),
     139              :                           )
     140              :                         : const Text(
     141              :                             '비밀번호 재설정 이메일 전송',
     142              :                             style: TextStyle(fontSize: 16),
     143              :                           ),
     144              :                   ),
     145              :                   const SizedBox(height: 16),
     146              : 
     147              :                   // 로그인 화면으로 돌아가기
     148            0 :                   Row(
     149              :                     mainAxisAlignment: MainAxisAlignment.center,
     150            0 :                     children: [
     151              :                       const Text('비밀번호가 기억나셨나요?'),
     152            0 :                       TextButton(
     153            0 :                         onPressed: () {
     154            0 :                           Navigator.pop(context); // 로그인 화면으로 돌아가기
     155              :                         },
     156              :                         child: const Text('로그인'),
     157              :                       ),
     158              :                     ],
     159              :                   ),
     160              :                 ],
     161              :               ),
     162              :             ),
     163              :           ),
     164              :         ),
     165              :       ),
     166              :     );
     167              :   }
     168              : }
        

Generated by: LCOV version 2.3.1-1