LCOV - code coverage report
Current view: top level - lib/screens/auth - profile_screen.dart Coverage Total Hit
Test: lcov.info Lines: 1.6 % 63 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              : import '../../models/user_model.dart';
       5              : 
       6              : class ProfileScreen extends StatefulWidget {
       7           24 :   const ProfileScreen({super.key});
       8              : 
       9            0 :   @override
      10            0 :   State<ProfileScreen> createState() => _ProfileScreenState();
      11              : }
      12              : 
      13              : class _ProfileScreenState extends State<ProfileScreen> {
      14              :   final _formKey = GlobalKey<FormState>();
      15              :   final _nameController = TextEditingController();
      16              :   bool _isEditing = false;
      17              : 
      18            0 :   @override
      19              :   void initState() {
      20            0 :     super.initState();
      21            0 :     WidgetsBinding.instance.addPostFrameCallback((_) {
      22            0 :       final user = Provider.of<AuthService>(context, listen: false).currentUser;
      23              :       if (user != null) {
      24            0 :         _nameController.text = user.name;
      25              :       }
      26              :     });
      27              :   }
      28              : 
      29            0 :   @override
      30              :   void dispose() {
      31            0 :     _nameController.dispose();
      32            0 :     super.dispose();
      33              :   }
      34              : 
      35            0 :   @override
      36              :   Widget build(BuildContext context) {
      37            0 :     return Scaffold(
      38            0 :       appBar: AppBar(
      39              :         title: const Text('내 프로필'),
      40            0 :         actions: [
      41            0 :           IconButton(
      42            0 :             icon: Icon(_isEditing ? Icons.save : Icons.edit),
      43            0 :             onPressed: () {
      44            0 :               setState(() {
      45            0 :                 _isEditing = !_isEditing;
      46              :               });
      47            0 :               if (!_isEditing) {
      48              :                 // 저장 로직 구현 (추후 개발)
      49            0 :                 if (_formKey.currentState!.validate()) {
      50            0 :                   ScaffoldMessenger.of(context).showSnackBar(
      51              :                     const SnackBar(content: Text('프로필이 업데이트되었습니다')),
      52              :                   );
      53              :                 }
      54              :               }
      55              :             },
      56              :           ),
      57              :         ],
      58              :       ),
      59            0 :       body: Consumer<AuthService>(
      60            0 :         builder: (context, authService, child) {
      61            0 :           final User? user = authService.currentUser;
      62              :           
      63              :           if (user == null) {
      64              :             return const Center(child: Text('사용자 정보를 불러올 수 없습니다'));
      65              :           }
      66              : 
      67            0 :           return SingleChildScrollView(
      68              :             padding: const EdgeInsets.all(16.0),
      69            0 :             child: Form(
      70            0 :               key: _formKey,
      71            0 :               child: Column(
      72              :                 crossAxisAlignment: CrossAxisAlignment.center,
      73            0 :                 children: [
      74              :                   // 프로필 이미지
      75            0 :                   CircleAvatar(
      76              :                     radius: 50,
      77            0 :                     backgroundImage: user.profileImage != null
      78            0 :                         ? NetworkImage(user.profileImage!)
      79              :                         : null,
      80            0 :                     child: user.profileImage == null
      81            0 :                         ? Text(
      82            0 :                             user.name.isNotEmpty ? user.name[0].toUpperCase() : '?',
      83              :                             style: const TextStyle(fontSize: 40),
      84              :                           )
      85              :                         : null,
      86              :                   ),
      87              :                   const SizedBox(height: 16),
      88              :                   
      89              :                   // 이름 필드
      90            0 :                   TextFormField(
      91            0 :                     controller: _nameController,
      92            0 :                     enabled: _isEditing,
      93              :                     decoration: const InputDecoration(
      94              :                       labelText: '이름',
      95              :                       border: OutlineInputBorder(),
      96              :                     ),
      97            0 :                     validator: (value) {
      98            0 :                       if (value == null || value.isEmpty) {
      99              :                         return '이름을 입력해주세요';
     100              :                       }
     101              :                       return null;
     102              :                     },
     103              :                   ),
     104              :                   const SizedBox(height: 16),
     105              :                   
     106              :                   // 이메일 (수정 불가)
     107            0 :                   TextFormField(
     108            0 :                     initialValue: user.email,
     109              :                     enabled: false,
     110              :                     decoration: const InputDecoration(
     111              :                       labelText: '이메일',
     112              :                       border: OutlineInputBorder(),
     113              :                     ),
     114              :                   ),
     115              :                   const SizedBox(height: 16),
     116              :                   
     117              :                   // 역할 표시
     118            0 :                   TextFormField(
     119            0 :                     initialValue: _getRoleDisplayName(user.role),
     120              :                     enabled: false,
     121              :                     decoration: const InputDecoration(
     122              :                       labelText: '역할',
     123              :                       border: OutlineInputBorder(),
     124              :                     ),
     125              :                   ),
     126              :                   const SizedBox(height: 16),
     127              :                   
     128              :                   // 클럽 역할 표시 (클럽이 있는 경우)
     129            0 :                   if (user.clubRole != null)
     130            0 :                     TextFormField(
     131            0 :                       initialValue: _getRoleDisplayName(user.clubRole!),
     132              :                       enabled: false,
     133              :                       decoration: const InputDecoration(
     134              :                         labelText: '클럽 내 역할',
     135              :                         border: OutlineInputBorder(),
     136              :                       ),
     137              :                     ),
     138            0 :                   const SizedBox(height: 32),
     139              :                   
     140              :                   // 로그아웃 버튼
     141            0 :                   ElevatedButton(
     142            0 :                     onPressed: () async {
     143            0 :                       await authService.logout();
     144            0 :                       if (context.mounted) {
     145            0 :                         Navigator.of(context).pushReplacementNamed('/login');
     146              :                       }
     147              :                     },
     148            0 :                     style: ElevatedButton.styleFrom(
     149              :                       backgroundColor: Colors.red,
     150              :                       foregroundColor: Colors.white,
     151              :                       padding: const EdgeInsets.symmetric(
     152              :                         horizontal: 32,
     153              :                         vertical: 12,
     154              :                       ),
     155              :                     ),
     156              :                     child: const Text('로그아웃'),
     157              :                   ),
     158              :                 ],
     159              :               ),
     160              :             ),
     161              :           );
     162              :         },
     163              :       ),
     164              :     );
     165              :   }
     166              : 
     167              :   // 역할 표시 이름 변환
     168            0 :   String _getRoleDisplayName(String role) {
     169              :     switch (role) {
     170            0 :       case 'admin':
     171              :         return '관리자';
     172            0 :       case 'superadmin':
     173              :         return '최고 관리자';
     174            0 :       case 'user':
     175              :         return '일반 사용자';
     176            0 :       case 'owner':
     177              :         return '클럽 소유자';
     178            0 :       case 'manager':
     179              :         return '클럽 매니저';
     180            0 :       case 'member':
     181              :         return '클럽 회원';
     182              :       default:
     183              :         return role;
     184              :     }
     185              :   }
     186              : }
        

Generated by: LCOV version 2.3.1-1