초기 커밋

This commit is contained in:
2026-03-01 07:55:59 +09:00
commit b0262d6bab
67 changed files with 4660 additions and 0 deletions

View File

@@ -0,0 +1,238 @@
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import 'package:go_router/go_router.dart';
import '../../../../core/router/route_names.dart';
import '../../../../core/utils/extensions.dart';
import '../../../../shared/widgets/chart_widgets/line_chart_widget.dart';
class AdminHomeScreen extends StatelessWidget {
const AdminHomeScreen({super.key});
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
padding: const EdgeInsets.all(24),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'관리자 대시보드',
style: context.textTheme.headlineMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
const Gap(8),
Text(
'시스템 현황을 한눈에 확인하세요',
style: context.textTheme.bodyLarge?.copyWith(
color: context.colorScheme.onSurfaceVariant,
),
),
const Gap(24),
// 통계 카드
LayoutBuilder(
builder: (context, constraints) {
final crossAxisCount = context.isDesktop
? 4
: context.isTablet
? 2
: 1;
return GridView.count(
crossAxisCount: crossAxisCount,
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
mainAxisSpacing: 16,
crossAxisSpacing: 16,
childAspectRatio: 1.8,
children: const [
_AdminStatCard(
title: '전체 사용자',
value: '1,234',
change: '+12%',
isPositive: true,
icon: Icons.people,
color: Colors.blue,
),
_AdminStatCard(
title: '활성 세션',
value: '89',
change: '+5%',
isPositive: true,
icon: Icons.devices,
color: Colors.green,
),
_AdminStatCard(
title: 'API 요청/분',
value: '2,456',
change: '-3%',
isPositive: false,
icon: Icons.api,
color: Colors.orange,
),
_AdminStatCard(
title: '시스템 오류',
value: '3',
change: '-50%',
isPositive: true,
icon: Icons.error_outline,
color: Colors.red,
),
],
);
},
),
const Gap(24),
// 차트 영역
SizedBox(
height: 300,
child: Card(
child: Padding(
padding: const EdgeInsets.all(20),
child: LineChartWidget(
title: '주간 사용자 활동',
spots: const [
FlSpot(0, 30),
FlSpot(1, 45),
FlSpot(2, 38),
FlSpot(3, 60),
FlSpot(4, 55),
FlSpot(5, 70),
FlSpot(6, 65),
],
bottomTitles: (value, meta) => SideTitleWidget(
meta: meta,
child: Text(
['', '', '', '', '', '', '']
[value.toInt() % 7],
style: Theme.of(context).textTheme.bodySmall,
),
),
),
),
),
),
const Gap(24),
// 빠른 링크
Text(
'빠른 액세스',
style: context.textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.bold,
),
),
const Gap(16),
Wrap(
spacing: 12,
runSpacing: 12,
children: [
_QuickAction(
icon: Icons.people,
label: '사용자 관리',
onTap: () => context.goNamed(RouteNames.adminUsers),
),
_QuickAction(
icon: Icons.dashboard,
label: '대시보드',
onTap: () => context.goNamed(RouteNames.adminDashboard),
),
_QuickAction(
icon: Icons.settings,
label: '시스템 설정',
onTap: () => context.goNamed(RouteNames.adminSettings),
),
],
),
],
),
);
}
}
class _AdminStatCard extends StatelessWidget {
const _AdminStatCard({
required this.title,
required this.value,
required this.change,
required this.isPositive,
required this.icon,
required this.color,
});
final String title;
final String value;
final String change;
final bool isPositive;
final IconData icon;
final Color color;
@override
Widget build(BuildContext context) {
return Card(
child: Padding(
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
title,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
Icon(icon, color: color, size: 24),
],
),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
value,
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
const Gap(8),
Text(
change,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: isPositive ? Colors.green : Colors.red,
fontWeight: FontWeight.w600,
),
),
],
),
],
),
),
);
}
}
class _QuickAction extends StatelessWidget {
const _QuickAction({
required this.icon,
required this.label,
required this.onTap,
});
final IconData icon;
final String label;
final VoidCallback onTap;
@override
Widget build(BuildContext context) {
return ActionChip(
avatar: Icon(icon),
label: Text(label),
onPressed: onTap,
);
}
}

View File

@@ -0,0 +1,231 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:gap/gap.dart';
import '../../../../app/app_providers.dart';
import '../../../../core/utils/extensions.dart';
class SystemSettingsScreen extends ConsumerWidget {
const SystemSettingsScreen({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final themeMode = ref.watch(themeModeNotifierProvider);
return SingleChildScrollView(
padding: const EdgeInsets.all(24),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'시스템 설정',
style: context.textTheme.headlineMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
const Gap(8),
Text(
'시스템 환경을 설정하세요',
style: context.textTheme.bodyLarge?.copyWith(
color: context.colorScheme.onSurfaceVariant,
),
),
const Gap(24),
// 일반 설정
Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 800),
child: Column(
children: [
_SettingsSection(
title: '일반',
children: [
_SettingsTile(
icon: Icons.brightness_6,
title: '테마',
subtitle: _themeLabel(themeMode),
trailing: SegmentedButton<ThemeMode>(
segments: const [
ButtonSegment(
value: ThemeMode.light,
icon: Icon(Icons.light_mode),
label: Text('라이트'),
),
ButtonSegment(
value: ThemeMode.system,
icon: Icon(Icons.brightness_auto),
label: Text('시스템'),
),
ButtonSegment(
value: ThemeMode.dark,
icon: Icon(Icons.dark_mode),
label: Text('다크'),
),
],
selected: {themeMode},
onSelectionChanged: (modes) {
ref
.read(themeModeNotifierProvider.notifier)
.setThemeMode(modes.first);
},
),
),
_SettingsTile(
icon: Icons.language,
title: '언어',
subtitle: '한국어',
trailing: const Icon(Icons.chevron_right),
onTap: () {
// TODO: 언어 설정
},
),
],
),
const Gap(16),
_SettingsSection(
title: '알림',
children: [
_SettingsTile(
icon: Icons.notifications,
title: '푸시 알림',
subtitle: '활성화됨',
trailing: Switch(
value: true,
onChanged: (value) {
// TODO: 알림 설정
},
),
),
_SettingsTile(
icon: Icons.email,
title: '이메일 알림',
subtitle: '활성화됨',
trailing: Switch(
value: true,
onChanged: (value) {
// TODO: 이메일 알림 설정
},
),
),
],
),
const Gap(16),
_SettingsSection(
title: 'API 설정',
children: [
_SettingsTile(
icon: Icons.link,
title: 'API Base URL',
subtitle: 'http://localhost:8000/api/v1',
trailing: const Icon(Icons.chevron_right),
onTap: () {
// TODO: API URL 설정
},
),
_SettingsTile(
icon: Icons.timer,
title: '요청 타임아웃',
subtitle: '15초',
trailing: const Icon(Icons.chevron_right),
onTap: () {
// TODO: 타임아웃 설정
},
),
],
),
const Gap(16),
_SettingsSection(
title: '정보',
children: [
const _SettingsTile(
icon: Icons.info_outline,
title: '앱 버전',
subtitle: '1.0.0',
),
const _SettingsTile(
icon: Icons.code,
title: 'Flutter',
subtitle: 'SDK 3.8.0',
),
],
),
],
),
),
),
],
),
);
}
String _themeLabel(ThemeMode mode) {
return switch (mode) {
ThemeMode.light => '라이트 모드',
ThemeMode.dark => '다크 모드',
ThemeMode.system => '시스템 설정',
};
}
}
class _SettingsSection extends StatelessWidget {
const _SettingsSection({
required this.title,
required this.children,
});
final String title;
final List<Widget> children;
@override
Widget build(BuildContext context) {
return Card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(20, 16, 20, 8),
child: Text(
title,
style: Theme.of(context).textTheme.titleSmall?.copyWith(
color: Theme.of(context).colorScheme.primary,
fontWeight: FontWeight.bold,
),
),
),
...children,
],
),
);
}
}
class _SettingsTile extends StatelessWidget {
const _SettingsTile({
required this.icon,
required this.title,
required this.subtitle,
this.trailing,
this.onTap,
});
final IconData icon;
final String title;
final String subtitle;
final Widget? trailing;
final VoidCallback? onTap;
@override
Widget build(BuildContext context) {
return ListTile(
leading: Icon(icon),
title: Text(title),
subtitle: Text(subtitle),
trailing: trailing,
onTap: onTap,
);
}
}

View File

@@ -0,0 +1,238 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:gap/gap.dart';
import 'package:pluto_grid/pluto_grid.dart';
import '../../../../core/utils/extensions.dart';
import '../../../../shared/widgets/confirm_dialog.dart';
class UserManagementScreen extends ConsumerStatefulWidget {
const UserManagementScreen({super.key});
@override
ConsumerState<UserManagementScreen> createState() =>
_UserManagementScreenState();
}
class _UserManagementScreenState extends ConsumerState<UserManagementScreen> {
late PlutoGridStateManager stateManager;
// Mock 데이터
final List<Map<String, dynamic>> _mockUsers = List.generate(
20,
(i) => {
'id': '${i + 1}',
'name': '사용자 ${i + 1}',
'email': 'user${i + 1}@example.com',
'role': i == 0 ? 'admin' : 'user',
'status': i % 5 == 0 ? '비활성' : '활성',
'created_at': '2025-01-${(i + 1).toString().padLeft(2, '0')}',
},
);
List<PlutoColumn> get _columns => [
PlutoColumn(
title: 'ID',
field: 'id',
type: PlutoColumnType.text(),
width: 60,
enableEditingMode: false,
),
PlutoColumn(
title: '이름',
field: 'name',
type: PlutoColumnType.text(),
width: 150,
),
PlutoColumn(
title: '이메일',
field: 'email',
type: PlutoColumnType.text(),
width: 250,
),
PlutoColumn(
title: '역할',
field: 'role',
type: PlutoColumnType.select(['admin', 'user']),
width: 100,
),
PlutoColumn(
title: '상태',
field: 'status',
type: PlutoColumnType.select(['활성', '비활성']),
width: 100,
),
PlutoColumn(
title: '가입일',
field: 'created_at',
type: PlutoColumnType.text(),
width: 150,
enableEditingMode: false,
),
];
List<PlutoRow> get _rows => _mockUsers
.map(
(user) => PlutoRow(
cells: {
'id': PlutoCell(value: user['id']),
'name': PlutoCell(value: user['name']),
'email': PlutoCell(value: user['email']),
'role': PlutoCell(value: user['role']),
'status': PlutoCell(value: user['status']),
'created_at': PlutoCell(value: user['created_at']),
},
),
)
.toList();
void _showCreateUserDialog() {
final nameController = TextEditingController();
final emailController = TextEditingController();
showDialog<void>(
context: context,
builder: (context) => AlertDialog(
title: const Text('새 사용자 추가'),
content: SizedBox(
width: 400,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextField(
controller: nameController,
decoration: const InputDecoration(
labelText: '이름',
hintText: '사용자 이름 입력',
),
),
const Gap(16),
TextField(
controller: emailController,
decoration: const InputDecoration(
labelText: '이메일',
hintText: 'email@example.com',
),
),
],
),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('취소'),
),
FilledButton(
onPressed: () {
// TODO: API 연동
Navigator.pop(context);
if (mounted) {
context.showSnackBar('사용자가 추가되었습니다');
}
},
child: const Text('추가'),
),
],
),
);
}
Future<void> _deleteUser(PlutoRow row) async {
final confirmed = await ConfirmDialog.show(
context,
title: '사용자 삭제',
message: '정말로 이 사용자를 삭제하시겠습니까? 이 작업은 되돌릴 수 없습니다.',
confirmLabel: '삭제',
isDestructive: true,
);
if (confirmed == true) {
stateManager.removeRows([row]);
if (mounted) {
context.showSnackBar('사용자가 삭제되었습니다');
}
}
}
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(24),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 헤더
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'사용자 관리',
style: context.textTheme.headlineMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
const Gap(4),
Text(
'사용자를 조회하고 관리하세요',
style: context.textTheme.bodyMedium?.copyWith(
color: context.colorScheme.onSurfaceVariant,
),
),
],
),
FilledButton.icon(
onPressed: _showCreateUserDialog,
icon: const Icon(Icons.person_add),
label: const Text('새 사용자'),
),
],
),
const Gap(24),
// 데이터 그리드
Expanded(
child: Card(
clipBehavior: Clip.antiAlias,
child: PlutoGrid(
columns: _columns,
rows: _rows,
onLoaded: (event) {
stateManager = event.stateManager;
},
onRowDoubleTap: (event) {
// TODO: 사용자 상세 정보 다이얼로그
},
configuration: PlutoGridConfiguration(
style: PlutoGridStyleConfig(
gridBackgroundColor:
context.colorScheme.surface,
rowColor: context.colorScheme.surface,
activatedColor:
context.colorScheme.primaryContainer,
activatedBorderColor: context.colorScheme.primary,
gridBorderColor:
context.colorScheme.outlineVariant,
borderColor:
context.colorScheme.outlineVariant,
cellTextStyle:
context.textTheme.bodyMedium!,
columnTextStyle:
context.textTheme.titleSmall!.copyWith(
fontWeight: FontWeight.bold,
),
),
columnSize: const PlutoGridColumnSizeConfig(
autoSizeMode: PlutoAutoSizeMode.scale,
),
),
),
),
),
],
),
);
}
}

View File

@@ -0,0 +1,28 @@
import 'package:dio/dio.dart';
import 'package:retrofit/retrofit.dart';
import '../../../../core/constants/api_constants.dart';
import '../models/login_request.dart';
import '../models/register_request.dart';
import '../models/token_response.dart';
part 'auth_remote_source.g.dart';
@RestApi()
abstract class AuthRemoteSource {
factory AuthRemoteSource(Dio dio) = _AuthRemoteSource;
@POST(ApiConstants.login)
Future<TokenResponse> login(@Body() LoginRequest request);
@POST(ApiConstants.register)
Future<TokenResponse> register(@Body() RegisterRequest request);
@POST(ApiConstants.logout)
Future<void> logout();
@POST(ApiConstants.refreshToken)
Future<TokenResponse> refreshToken(
@Body() Map<String, String> body,
);
}

View File

@@ -0,0 +1,15 @@
import 'package:freezed_annotation/freezed_annotation.dart';
part 'login_request.freezed.dart';
part 'login_request.g.dart';
@freezed
class LoginRequest with _$LoginRequest {
const factory LoginRequest({
required String email,
required String password,
}) = _LoginRequest;
factory LoginRequest.fromJson(Map<String, dynamic> json) =>
_$LoginRequestFromJson(json);
}

View File

@@ -0,0 +1,16 @@
import 'package:freezed_annotation/freezed_annotation.dart';
part 'register_request.freezed.dart';
part 'register_request.g.dart';
@freezed
class RegisterRequest with _$RegisterRequest {
const factory RegisterRequest({
required String email,
required String password,
required String name,
}) = _RegisterRequest;
factory RegisterRequest.fromJson(Map<String, dynamic> json) =>
_$RegisterRequestFromJson(json);
}

View File

@@ -0,0 +1,16 @@
import 'package:freezed_annotation/freezed_annotation.dart';
part 'token_response.freezed.dart';
part 'token_response.g.dart';
@freezed
class TokenResponse with _$TokenResponse {
const factory TokenResponse({
@JsonKey(name: 'access_token') required String accessToken,
@JsonKey(name: 'refresh_token') required String refreshToken,
@JsonKey(name: 'token_type') @Default('bearer') String tokenType,
}) = _TokenResponse;
factory TokenResponse.fromJson(Map<String, dynamic> json) =>
_$TokenResponseFromJson(json);
}

View File

@@ -0,0 +1,123 @@
import 'dart:convert';
import 'package:talker/talker.dart';
import '../../../../core/constants/app_constants.dart';
import '../../../../core/error/exceptions.dart';
import '../../../../core/storage/secure_storage.dart';
import '../../../../shared/models/user_role.dart';
import '../../domain/entities/user.dart';
import '../../domain/repositories/auth_repository.dart';
import '../datasources/auth_remote_source.dart';
import '../models/login_request.dart';
import '../models/register_request.dart';
class AuthRepositoryImpl implements AuthRepository {
AuthRepositoryImpl({
required this.remoteSource,
required this.secureStorage,
required this.talker,
});
final AuthRemoteSource remoteSource;
final SecureStorage secureStorage;
final Talker talker;
@override
Future<User> login({
required String email,
required String password,
}) async {
try {
final response = await remoteSource.login(
LoginRequest(email: email, password: password),
);
await _saveTokens(response.accessToken, response.refreshToken);
// 로그인 후 사용자 정보 조회
final user = await getCurrentUser();
if (user == null) {
throw const ServerException(
message: '사용자 정보를 가져올 수 없습니다',
statusCode: 500,
);
}
return user;
} catch (e) {
talker.error('Login failed', e);
rethrow;
}
}
@override
Future<User> register({
required String email,
required String password,
required String name,
}) async {
try {
final response = await remoteSource.register(
RegisterRequest(email: email, password: password, name: name),
);
await _saveTokens(response.accessToken, response.refreshToken);
return User(
id: '',
email: email,
name: name,
role: UserRole.user,
);
} catch (e) {
talker.error('Register failed', e);
rethrow;
}
}
@override
Future<void> logout() async {
try {
await remoteSource.logout();
} catch (_) {
// 서버 로그아웃 실패해도 로컬 토큰은 삭제
} finally {
await secureStorage.delete(key: AppConstants.accessTokenKey);
await secureStorage.delete(key: AppConstants.refreshTokenKey);
await secureStorage.delete(key: AppConstants.userKey);
}
}
@override
Future<User?> getCurrentUser() async {
try {
final userData = await secureStorage.read(key: AppConstants.userKey);
if (userData != null) {
return User.fromJson(
jsonDecode(userData) as Map<String, dynamic>,
);
}
return null;
} catch (e) {
talker.error('Get current user failed', e);
return null;
}
}
@override
Future<bool> isLoggedIn() async {
final token = await secureStorage.read(key: AppConstants.accessTokenKey);
return token != null;
}
Future<void> _saveTokens(String accessToken, String refreshToken) async {
await secureStorage.write(
key: AppConstants.accessTokenKey,
value: accessToken,
);
await secureStorage.write(
key: AppConstants.refreshTokenKey,
value: refreshToken,
);
}
}

View File

@@ -0,0 +1,22 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import '../../../../shared/models/user_role.dart';
part 'user.freezed.dart';
part 'user.g.dart';
@freezed
class User with _$User {
const factory User({
required String id,
required String email,
required String name,
@Default(UserRole.user) UserRole role,
String? avatarUrl,
DateTime? createdAt,
DateTime? lastLoginAt,
@Default(true) bool isActive,
}) = _User;
factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json);
}

View File

@@ -0,0 +1,20 @@
import '../entities/user.dart';
abstract class AuthRepository {
Future<User> login({
required String email,
required String password,
});
Future<User> register({
required String email,
required String password,
required String name,
});
Future<void> logout();
Future<User?> getCurrentUser();
Future<bool> isLoggedIn();
}

View File

@@ -0,0 +1,15 @@
import '../../domain/entities/user.dart';
import '../../domain/repositories/auth_repository.dart';
class LoginUseCase {
LoginUseCase({required this.repository});
final AuthRepository repository;
Future<User> call({
required String email,
required String password,
}) {
return repository.login(email: email, password: password);
}
}

View File

@@ -0,0 +1,9 @@
import '../../domain/repositories/auth_repository.dart';
class LogoutUseCase {
LogoutUseCase({required this.repository});
final AuthRepository repository;
Future<void> call() => repository.logout();
}

View File

@@ -0,0 +1,20 @@
import '../../domain/entities/user.dart';
import '../../domain/repositories/auth_repository.dart';
class RegisterUseCase {
RegisterUseCase({required this.repository});
final AuthRepository repository;
Future<User> call({
required String email,
required String password,
required String name,
}) {
return repository.register(
email: email,
password: password,
name: name,
);
}
}

View File

@@ -0,0 +1,78 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import '../../../../core/logging/app_logger.dart';
import '../../../../core/network/dio_client.dart';
import '../../../../core/storage/secure_storage.dart';
import '../../data/datasources/auth_remote_source.dart';
import '../../data/repositories/auth_repository_impl.dart';
import '../../domain/entities/user.dart';
import '../../domain/repositories/auth_repository.dart';
part 'auth_providers.g.dart';
@Riverpod(keepAlive: true)
AuthRemoteSource authRemoteSource(Ref ref) {
final dio = ref.read(dioProvider);
return AuthRemoteSource(dio);
}
@Riverpod(keepAlive: true)
AuthRepository authRepository(Ref ref) {
return AuthRepositoryImpl(
remoteSource: ref.read(authRemoteSourceProvider),
secureStorage: ref.read(secureStorageProvider),
talker: ref.read(appLoggerProvider),
);
}
@riverpod
class LoginNotifier extends _$LoginNotifier {
@override
FutureOr<void> build() {}
Future<User?> login({
required String email,
required String password,
}) async {
state = const AsyncLoading();
final result = await AsyncValue.guard(() async {
final repository = ref.read(authRepositoryProvider);
return repository.login(email: email, password: password);
});
state = result.hasError
? AsyncError(result.error!, result.stackTrace!)
: const AsyncData(null);
return result.valueOrNull;
}
}
@riverpod
class RegisterNotifier extends _$RegisterNotifier {
@override
FutureOr<void> build() {}
Future<User?> register({
required String email,
required String password,
required String name,
}) async {
state = const AsyncLoading();
final result = await AsyncValue.guard(() async {
final repository = ref.read(authRepositoryProvider);
return repository.register(
email: email,
password: password,
name: name,
);
});
state = result.hasError
? AsyncError(result.error!, result.stackTrace!)
: const AsyncData(null);
return result.valueOrNull;
}
}

View File

@@ -0,0 +1,27 @@
import 'package:flutter/material.dart';
import '../widgets/login_form.dart';
class LoginScreen extends StatelessWidget {
const LoginScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: SingleChildScrollView(
padding: const EdgeInsets.all(24),
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 400),
child: const Card(
child: Padding(
padding: EdgeInsets.all(32),
child: LoginForm(),
),
),
),
),
),
);
}
}

View File

@@ -0,0 +1,27 @@
import 'package:flutter/material.dart';
import '../widgets/register_form.dart';
class RegisterScreen extends StatelessWidget {
const RegisterScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: SingleChildScrollView(
padding: const EdgeInsets.all(24),
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 400),
child: const Card(
child: Padding(
padding: EdgeInsets.all(32),
child: RegisterForm(),
),
),
),
),
),
);
}
}

View File

@@ -0,0 +1,148 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:gap/gap.dart';
import 'package:go_router/go_router.dart';
import 'package:reactive_forms/reactive_forms.dart';
import '../../../../core/router/route_names.dart';
import '../../../../core/utils/extensions.dart';
import '../../../../shared/providers/auth_provider.dart';
import '../providers/auth_providers.dart';
class LoginForm extends ConsumerStatefulWidget {
const LoginForm({super.key});
@override
ConsumerState<LoginForm> createState() => _LoginFormState();
}
class _LoginFormState extends ConsumerState<LoginForm> {
late final FormGroup form;
@override
void initState() {
super.initState();
form = FormGroup({
'email': FormControl<String>(
validators: [Validators.required, Validators.email],
),
'password': FormControl<String>(
validators: [Validators.required, Validators.minLength(8)],
),
});
}
@override
void dispose() {
form.dispose();
super.dispose();
}
Future<void> _onSubmit() async {
if (!form.valid) {
form.markAllAsTouched();
return;
}
final email = form.control('email').value as String;
final password = form.control('password').value as String;
final user = await ref.read(loginNotifierProvider.notifier).login(
email: email,
password: password,
);
if (user != null && mounted) {
ref.read(authStateProvider.notifier).setUser(user);
}
}
@override
Widget build(BuildContext context) {
final loginState = ref.watch(loginNotifierProvider);
ref.listen(loginNotifierProvider, (_, state) {
if (state.hasError) {
context.showSnackBar(
'로그인에 실패했습니다. 이메일과 비밀번호를 확인해주세요.',
isError: true,
);
}
});
return ReactiveForm(
formGroup: form,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: [
Text(
'로그인',
style: context.textTheme.headlineMedium?.copyWith(
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
const Gap(8),
Text(
'계정에 로그인하세요',
style: context.textTheme.bodyMedium?.copyWith(
color: context.colorScheme.onSurfaceVariant,
),
textAlign: TextAlign.center,
),
const Gap(32),
ReactiveTextField<String>(
formControlName: 'email',
decoration: const InputDecoration(
labelText: '이메일',
hintText: 'email@example.com',
prefixIcon: Icon(Icons.email_outlined),
),
keyboardType: TextInputType.emailAddress,
validationMessages: {
'required': (_) => '이메일을 입력해주세요',
'email': (_) => '올바른 이메일 형식이 아닙니다',
},
),
const Gap(16),
ReactiveTextField<String>(
formControlName: 'password',
decoration: const InputDecoration(
labelText: '비밀번호',
hintText: '8자 이상 입력',
prefixIcon: Icon(Icons.lock_outlined),
),
obscureText: true,
validationMessages: {
'required': (_) => '비밀번호를 입력해주세요',
'minLength': (_) => '비밀번호는 8자 이상이어야 합니다',
},
),
const Gap(24),
FilledButton(
onPressed: loginState.isLoading ? null : _onSubmit,
child: loginState.isLoading
? const SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(strokeWidth: 2),
)
: const Text('로그인'),
),
const Gap(16),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('계정이 없으신가요?'),
TextButton(
onPressed: () => context.goNamed(RouteNames.register),
child: const Text('회원가입'),
),
],
),
],
),
);
}
}

View File

@@ -0,0 +1,184 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:gap/gap.dart';
import 'package:go_router/go_router.dart';
import 'package:reactive_forms/reactive_forms.dart';
import '../../../../core/router/route_names.dart';
import '../../../../core/utils/extensions.dart';
import '../../../../shared/providers/auth_provider.dart';
import '../providers/auth_providers.dart';
class RegisterForm extends ConsumerStatefulWidget {
const RegisterForm({super.key});
@override
ConsumerState<RegisterForm> createState() => _RegisterFormState();
}
class _RegisterFormState extends ConsumerState<RegisterForm> {
late final FormGroup form;
@override
void initState() {
super.initState();
form = FormGroup({
'name': FormControl<String>(
validators: [Validators.required],
),
'email': FormControl<String>(
validators: [Validators.required, Validators.email],
),
'password': FormControl<String>(
validators: [Validators.required, Validators.minLength(8)],
),
'confirmPassword': FormControl<String>(
validators: [Validators.required],
),
}, validators: [
Validators.mustMatch('password', 'confirmPassword'),
]);
}
@override
void dispose() {
form.dispose();
super.dispose();
}
Future<void> _onSubmit() async {
if (!form.valid) {
form.markAllAsTouched();
return;
}
final name = form.control('name').value as String;
final email = form.control('email').value as String;
final password = form.control('password').value as String;
final user = await ref.read(registerNotifierProvider.notifier).register(
email: email,
password: password,
name: name,
);
if (user != null && mounted) {
ref.read(authStateProvider.notifier).setUser(user);
}
}
@override
Widget build(BuildContext context) {
final registerState = ref.watch(registerNotifierProvider);
ref.listen(registerNotifierProvider, (_, state) {
if (state.hasError) {
context.showSnackBar(
'회원가입에 실패했습니다. 입력 정보를 확인해주세요.',
isError: true,
);
}
});
return ReactiveForm(
formGroup: form,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: [
Text(
'회원가입',
style: context.textTheme.headlineMedium?.copyWith(
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
const Gap(8),
Text(
'새 계정을 만드세요',
style: context.textTheme.bodyMedium?.copyWith(
color: context.colorScheme.onSurfaceVariant,
),
textAlign: TextAlign.center,
),
const Gap(32),
ReactiveTextField<String>(
formControlName: 'name',
decoration: const InputDecoration(
labelText: '이름',
hintText: '홍길동',
prefixIcon: Icon(Icons.person_outlined),
),
validationMessages: {
'required': (_) => '이름을 입력해주세요',
},
),
const Gap(16),
ReactiveTextField<String>(
formControlName: 'email',
decoration: const InputDecoration(
labelText: '이메일',
hintText: 'email@example.com',
prefixIcon: Icon(Icons.email_outlined),
),
keyboardType: TextInputType.emailAddress,
validationMessages: {
'required': (_) => '이메일을 입력해주세요',
'email': (_) => '올바른 이메일 형식이 아닙니다',
},
),
const Gap(16),
ReactiveTextField<String>(
formControlName: 'password',
decoration: const InputDecoration(
labelText: '비밀번호',
hintText: '8자 이상 입력',
prefixIcon: Icon(Icons.lock_outlined),
),
obscureText: true,
validationMessages: {
'required': (_) => '비밀번호를 입력해주세요',
'minLength': (_) => '비밀번호는 8자 이상이어야 합니다',
},
),
const Gap(16),
ReactiveTextField<String>(
formControlName: 'confirmPassword',
decoration: const InputDecoration(
labelText: '비밀번호 확인',
hintText: '비밀번호를 다시 입력',
prefixIcon: Icon(Icons.lock_outlined),
),
obscureText: true,
validationMessages: {
'required': (_) => '비밀번호 확인을 입력해주세요',
'mustMatch': (_) => '비밀번호가 일치하지 않습니다',
},
),
const Gap(24),
FilledButton(
onPressed: registerState.isLoading ? null : _onSubmit,
child: registerState.isLoading
? const SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(strokeWidth: 2),
)
: const Text('회원가입'),
),
const Gap(16),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('이미 계정이 있으신가요?'),
TextButton(
onPressed: () => context.goNamed(RouteNames.login),
child: const Text('로그인'),
),
],
),
],
),
);
}
}

View File

@@ -0,0 +1,265 @@
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import '../../../../core/utils/extensions.dart';
import '../../../../shared/widgets/chart_widgets/bar_chart_widget.dart';
import '../../../../shared/widgets/chart_widgets/pie_chart_widget.dart';
import '../widgets/monitoring_panel.dart';
import '../widgets/realtime_chart.dart';
import '../widgets/stats_card.dart';
class DashboardScreen extends StatelessWidget {
const DashboardScreen({super.key});
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
padding: const EdgeInsets.all(24),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'대시보드',
style: context.textTheme.headlineMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
const Gap(8),
Text(
'실시간 데이터와 시스템 현황을 모니터링하세요',
style: context.textTheme.bodyLarge?.copyWith(
color: context.colorScheme.onSurfaceVariant,
),
),
const Gap(24),
// 통계 카드
LayoutBuilder(
builder: (context, constraints) {
final crossAxisCount = context.isDesktop
? 4
: context.isTablet
? 2
: 1;
return GridView.count(
crossAxisCount: crossAxisCount,
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
mainAxisSpacing: 16,
crossAxisSpacing: 16,
childAspectRatio: 1.8,
children: const [
StatsCard(
title: '총 사용자',
value: '1,234',
icon: Icons.people,
iconColor: Colors.blue,
change: '+12%',
isPositive: true,
subtitle: '전월 대비',
),
StatsCard(
title: '활성 세션',
value: '89',
icon: Icons.devices,
iconColor: Colors.green,
change: '+5',
isPositive: true,
subtitle: '현재 접속',
),
StatsCard(
title: '요청 수',
value: '24.5K',
icon: Icons.trending_up,
iconColor: Colors.orange,
change: '+18%',
isPositive: true,
subtitle: '오늘',
),
StatsCard(
title: '평균 응답시간',
value: '142ms',
icon: Icons.speed,
iconColor: Colors.purple,
change: '-8ms',
isPositive: true,
subtitle: '지난 1시간',
),
],
);
},
),
const Gap(24),
// 실시간 차트 + 모니터링 패널
LayoutBuilder(
builder: (context, constraints) {
if (context.isDesktop) {
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Expanded(
flex: 2,
child: SizedBox(
height: 350,
child: RealtimeChart(
title: '실시간 트래픽',
),
),
),
const Gap(16),
const Expanded(
child: MonitoringPanel(),
),
],
);
}
return Column(
children: const [
SizedBox(
height: 350,
child: RealtimeChart(
title: '실시간 트래픽',
),
),
Gap(16),
MonitoringPanel(),
],
);
},
),
const Gap(24),
// 바 차트 + 파이 차트
LayoutBuilder(
builder: (context, constraints) {
final charts = [
SizedBox(
height: 300,
child: Card(
child: Padding(
padding: const EdgeInsets.all(20),
child: BarChartWidget(
title: '일별 API 요청',
maxY: 100,
barGroups: List.generate(
7,
(i) => BarChartGroupData(
x: i,
barRods: [
BarChartRodData(
toY: [30, 45, 60, 38, 72, 55, 40][i]
.toDouble(),
color:
context.colorScheme.primary,
width: 16,
borderRadius:
const BorderRadius.vertical(
top: Radius.circular(4),
),
),
],
),
),
bottomTitles: (value, meta) => SideTitleWidget(
meta: meta,
child: Text(
['', '', '', '', '', '', '']
[value.toInt() % 7],
style: Theme.of(context).textTheme.bodySmall,
),
),
),
),
),
),
SizedBox(
height: 300,
child: Card(
child: Padding(
padding: const EdgeInsets.all(20),
child: PieChartWidget(
title: '사용자 분포',
sections: [
PieChartSectionData(
value: 45,
color: Colors.blue,
title: '45%',
radius: 50,
titleStyle: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 12,
),
),
PieChartSectionData(
value: 30,
color: Colors.green,
title: '30%',
radius: 50,
titleStyle: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 12,
),
),
PieChartSectionData(
value: 15,
color: Colors.orange,
title: '15%',
radius: 50,
titleStyle: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 12,
),
),
PieChartSectionData(
value: 10,
color: Colors.purple,
title: '10%',
radius: 50,
titleStyle: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 12,
),
),
],
legendItems: const [
LegendItem(label: '', color: Colors.blue),
LegendItem(label: 'Android', color: Colors.green),
LegendItem(label: 'iOS', color: Colors.orange),
LegendItem(label: '기타', color: Colors.purple),
],
),
),
),
),
];
if (context.isDesktop) {
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(child: charts[0]),
const Gap(16),
Expanded(child: charts[1]),
],
);
}
return Column(
children: [
charts[0],
const Gap(16),
charts[1],
],
);
},
),
],
),
);
}
}

View File

@@ -0,0 +1,187 @@
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
class MonitoringPanel extends StatelessWidget {
const MonitoringPanel({super.key});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Card(
child: Padding(
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'시스템 모니터링',
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
const Gap(16),
_MonitoringItem(
label: 'CPU 사용률',
value: 0.45,
displayValue: '45%',
color: Colors.blue,
),
const Gap(12),
_MonitoringItem(
label: '메모리 사용률',
value: 0.62,
displayValue: '62%',
color: Colors.orange,
),
const Gap(12),
_MonitoringItem(
label: '디스크 사용률',
value: 0.35,
displayValue: '35%',
color: Colors.green,
),
const Gap(12),
_MonitoringItem(
label: '네트워크 I/O',
value: 0.78,
displayValue: '78 Mbps',
color: Colors.purple,
),
const Gap(16),
const Divider(),
const Gap(12),
// 서비스 상태
Text(
'서비스 상태',
style: theme.textTheme.titleSmall?.copyWith(
fontWeight: FontWeight.bold,
),
),
const Gap(12),
const _ServiceStatus(
name: 'API 서버',
status: ServiceState.running,
),
const _ServiceStatus(
name: 'WebSocket',
status: ServiceState.running,
),
const _ServiceStatus(
name: '데이터베이스',
status: ServiceState.running,
),
const _ServiceStatus(
name: '캐시 서버',
status: ServiceState.warning,
),
],
),
),
);
}
}
class _MonitoringItem extends StatelessWidget {
const _MonitoringItem({
required this.label,
required this.value,
required this.displayValue,
required this.color,
});
final String label;
final double value;
final String displayValue;
final Color color;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(label, style: theme.textTheme.bodyMedium),
Text(
displayValue,
style: theme.textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.w600,
),
),
],
),
const Gap(6),
ClipRRect(
borderRadius: BorderRadius.circular(4),
child: LinearProgressIndicator(
value: value,
backgroundColor: color.withValues(alpha: 0.1),
valueColor: AlwaysStoppedAnimation(color),
minHeight: 8,
),
),
],
);
}
}
enum ServiceState { running, stopped, warning }
class _ServiceStatus extends StatelessWidget {
const _ServiceStatus({
required this.name,
required this.status,
});
final String name;
final ServiceState status;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final (color, label) = switch (status) {
ServiceState.running => (Colors.green, '정상'),
ServiceState.stopped => (Colors.red, '중지'),
ServiceState.warning => (Colors.orange, '경고'),
};
return Padding(
padding: const EdgeInsets.symmetric(vertical: 6),
child: Row(
children: [
Container(
width: 10,
height: 10,
decoration: BoxDecoration(
color: color,
shape: BoxShape.circle,
),
),
const Gap(10),
Expanded(
child: Text(name, style: theme.textTheme.bodyMedium),
),
Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
decoration: BoxDecoration(
color: color.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(4),
),
child: Text(
label,
style: theme.textTheme.bodySmall?.copyWith(
color: color,
fontWeight: FontWeight.w600,
),
),
),
],
),
);
}
}

View File

@@ -0,0 +1,182 @@
import 'dart:async';
import 'dart:math';
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
class RealtimeChart extends StatefulWidget {
const RealtimeChart({
this.title = '실시간 데이터',
this.dataStream,
this.maxDataPoints = 30,
this.lineColor,
super.key,
});
final String title;
final Stream<double>? dataStream;
final int maxDataPoints;
final Color? lineColor;
@override
State<RealtimeChart> createState() => _RealtimeChartState();
}
class _RealtimeChartState extends State<RealtimeChart> {
final List<FlSpot> _spots = [];
StreamSubscription<double>? _subscription;
Timer? _mockTimer;
int _index = 0;
final _random = Random();
@override
void initState() {
super.initState();
if (widget.dataStream != null) {
_subscription = widget.dataStream!.listen(_addDataPoint);
} else {
// Mock 데이터 생성 (WebSocket 미연결 시)
_mockTimer = Timer.periodic(const Duration(seconds: 1), (_) {
_addDataPoint(50 + _random.nextDouble() * 50);
});
}
}
void _addDataPoint(double value) {
setState(() {
_spots.add(FlSpot(_index.toDouble(), value));
if (_spots.length > widget.maxDataPoints) {
_spots.removeAt(0);
}
_index++;
});
}
@override
void dispose() {
_subscription?.cancel();
_mockTimer?.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final color = widget.lineColor ?? theme.colorScheme.primary;
return Card(
child: Padding(
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
widget.title,
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 4,
),
decoration: BoxDecoration(
color: Colors.green.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(12),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 8,
height: 8,
decoration: const BoxDecoration(
color: Colors.green,
shape: BoxShape.circle,
),
),
const Gap(4),
Text(
'LIVE',
style: theme.textTheme.bodySmall?.copyWith(
color: Colors.green,
fontWeight: FontWeight.bold,
),
),
],
),
),
],
),
const Gap(16),
Expanded(
child: _spots.length < 2
? const Center(child: CircularProgressIndicator())
: LineChart(
LineChartData(
gridData: FlGridData(
show: true,
drawVerticalLine: false,
horizontalInterval: 25,
getDrawingHorizontalLine: (value) => FlLine(
color: theme.colorScheme.outlineVariant
.withValues(alpha: 0.3),
strokeWidth: 1,
),
),
titlesData: const FlTitlesData(
topTitles: AxisTitles(
sideTitles: SideTitles(showTitles: false),
),
rightTitles: AxisTitles(
sideTitles: SideTitles(showTitles: false),
),
bottomTitles: AxisTitles(
sideTitles: SideTitles(showTitles: false),
),
leftTitles: AxisTitles(
sideTitles: SideTitles(
showTitles: true,
reservedSize: 40,
),
),
),
borderData: FlBorderData(show: false),
minY: 0,
maxY: 100,
lineBarsData: [
LineChartBarData(
spots: _spots,
isCurved: true,
color: color,
barWidth: 2,
isStrokeCapRound: true,
dotData: const FlDotData(show: false),
belowBarData: BarAreaData(
show: true,
gradient: LinearGradient(
colors: [
color.withValues(alpha: 0.3),
color.withValues(alpha: 0.0),
],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
),
),
],
),
duration: const Duration(milliseconds: 150),
),
),
],
),
),
);
}
}

View File

@@ -0,0 +1,105 @@
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
class StatsCard extends StatelessWidget {
const StatsCard({
required this.title,
required this.value,
this.icon,
this.iconColor,
this.change,
this.isPositive,
this.subtitle,
super.key,
});
final String title;
final String value;
final IconData? icon;
final Color? iconColor;
final String? change;
final bool? isPositive;
final String? subtitle;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Card(
child: Padding(
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text(
title,
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
overflow: TextOverflow.ellipsis,
),
),
if (icon != null)
Icon(
icon,
color: iconColor ?? theme.colorScheme.primary,
size: 24,
),
],
),
const Gap(8),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
value,
style: theme.textTheme.headlineMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
if (change != null) ...[
const Gap(8),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 6,
vertical: 2,
),
decoration: BoxDecoration(
color: (isPositive ?? true)
? Colors.green.withValues(alpha: 0.1)
: Colors.red.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(4),
),
child: Text(
change!,
style: theme.textTheme.bodySmall?.copyWith(
color: (isPositive ?? true)
? Colors.green
: Colors.red,
fontWeight: FontWeight.w600,
),
),
),
],
],
),
if (subtitle != null) ...[
const Gap(4),
Text(
subtitle!,
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
),
],
],
),
),
);
}
}

View File

@@ -0,0 +1,166 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:gap/gap.dart';
import '../../../../core/utils/extensions.dart';
import '../../../../shared/providers/auth_provider.dart';
class UserHomeScreen extends ConsumerWidget {
const UserHomeScreen({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final authState = ref.watch(authStateProvider);
return SingleChildScrollView(
padding: const EdgeInsets.all(24),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 환영 메시지
authState.when(
data: (user) => Text(
'안녕하세요, ${user?.name ?? '사용자'}님!',
style: context.textTheme.headlineMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
loading: () => const SizedBox.shrink(),
error: (_, __) => const SizedBox.shrink(),
),
const Gap(8),
Text(
'오늘의 요약을 확인하세요',
style: context.textTheme.bodyLarge?.copyWith(
color: context.colorScheme.onSurfaceVariant,
),
),
const Gap(24),
// 요약 카드 그리드
LayoutBuilder(
builder: (context, constraints) {
final crossAxisCount = context.isDesktop
? 4
: context.isTablet
? 2
: 1;
return GridView.count(
crossAxisCount: crossAxisCount,
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
mainAxisSpacing: 16,
crossAxisSpacing: 16,
childAspectRatio: 1.8,
children: const [
_SummaryCard(
title: '진행중 작업',
value: '12',
icon: Icons.pending_actions,
color: Colors.blue,
),
_SummaryCard(
title: '완료된 작업',
value: '48',
icon: Icons.check_circle_outline,
color: Colors.green,
),
_SummaryCard(
title: '알림',
value: '3',
icon: Icons.notifications_outlined,
color: Colors.orange,
),
_SummaryCard(
title: '메시지',
value: '7',
icon: Icons.mail_outlined,
color: Colors.purple,
),
],
);
},
),
const Gap(24),
// 최근 활동
Text(
'최근 활동',
style: context.textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.bold,
),
),
const Gap(16),
Card(
child: ListView.separated(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: 5,
separatorBuilder: (_, __) => const Divider(height: 1),
itemBuilder: (context, index) => ListTile(
leading: CircleAvatar(
backgroundColor:
context.colorScheme.primaryContainer,
child: Icon(
Icons.task_alt,
color: context.colorScheme.primary,
),
),
title: Text('활동 항목 ${index + 1}'),
subtitle: Text('${index + 1}시간 전'),
trailing: const Icon(Icons.chevron_right),
),
),
),
],
),
);
}
}
class _SummaryCard extends StatelessWidget {
const _SummaryCard({
required this.title,
required this.value,
required this.icon,
required this.color,
});
final String title;
final String value;
final IconData icon;
final Color color;
@override
Widget build(BuildContext context) {
return Card(
child: Padding(
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
title,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
Icon(icon, color: color, size: 24),
],
),
Text(
value,
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
],
),
),
);
}
}

View File

@@ -0,0 +1,172 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:gap/gap.dart';
import '../../../../core/utils/extensions.dart';
import '../../../../shared/providers/auth_provider.dart';
class UserProfileScreen extends ConsumerWidget {
const UserProfileScreen({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final authState = ref.watch(authStateProvider);
return SingleChildScrollView(
padding: const EdgeInsets.all(24),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'프로필',
style: context.textTheme.headlineMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
const Gap(24),
// 프로필 카드
Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 600),
child: Card(
child: Padding(
padding: const EdgeInsets.all(32),
child: authState.when(
data: (user) => Column(
children: [
// 아바타
CircleAvatar(
radius: 50,
backgroundColor:
context.colorScheme.primaryContainer,
child: Text(
(user?.name ?? 'U').substring(0, 1).toUpperCase(),
style: context.textTheme.headlineLarge?.copyWith(
color: context.colorScheme.primary,
),
),
),
const Gap(16),
Text(
user?.name ?? '사용자',
style: context.textTheme.headlineSmall?.copyWith(
fontWeight: FontWeight.bold,
),
),
const Gap(4),
Text(
user?.email ?? '',
style: context.textTheme.bodyLarge?.copyWith(
color: context.colorScheme.onSurfaceVariant,
),
),
const Gap(8),
Chip(
label: Text(
user?.role.value.toUpperCase() ?? 'USER',
),
backgroundColor:
context.colorScheme.secondaryContainer,
),
const Gap(32),
const Divider(),
const Gap(16),
// 프로필 정보 목록
_ProfileInfoTile(
icon: Icons.person_outlined,
label: '이름',
value: user?.name ?? '-',
),
_ProfileInfoTile(
icon: Icons.email_outlined,
label: '이메일',
value: user?.email ?? '-',
),
_ProfileInfoTile(
icon: Icons.shield_outlined,
label: '역할',
value: user?.role.value ?? '-',
),
_ProfileInfoTile(
icon: Icons.calendar_today_outlined,
label: '가입일',
value: user?.createdAt?.toString().split(' ').first ??
'-',
),
const Gap(24),
// 프로필 수정 버튼
SizedBox(
width: double.infinity,
child: FilledButton.icon(
onPressed: () {
// TODO: 프로필 수정 기능
},
icon: const Icon(Icons.edit),
label: const Text('프로필 수정'),
),
),
],
),
loading: () => const Center(
child: CircularProgressIndicator(),
),
error: (error, _) => Center(
child: Text('오류: $error'),
),
),
),
),
),
),
],
),
);
}
}
class _ProfileInfoTile extends StatelessWidget {
const _ProfileInfoTile({
required this.icon,
required this.label,
required this.value,
});
final IconData icon;
final String label;
final String value;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: Row(
children: [
Icon(
icon,
size: 20,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
const Gap(12),
SizedBox(
width: 80,
child: Text(
label,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
),
Expanded(
child: Text(
value,
style: Theme.of(context).textTheme.bodyMedium,
),
),
],
),
);
}
}