import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:shadcn_ui/shadcn_ui.dart'; import '../../../../core/constants/app_sections.dart'; class LoginPage extends StatefulWidget { const LoginPage({super.key}); @override State createState() => _LoginPageState(); } class _LoginPageState extends State { final idController = TextEditingController(); final passwordController = TextEditingController(); bool rememberMe = false; bool isLoading = false; String? errorMessage; @override void dispose() { idController.dispose(); passwordController.dispose(); super.dispose(); } Future _handleSubmit() async { if (isLoading) return; setState(() { errorMessage = null; isLoading = true; }); final id = idController.text.trim(); final password = passwordController.text.trim(); await Future.delayed(const Duration(milliseconds: 600)); if (id.isEmpty || password.isEmpty) { setState(() { errorMessage = '아이디와 비밀번호를 모두 입력하세요.'; isLoading = false; }); return; } if (password.length < 6) { setState(() { errorMessage = '비밀번호는 6자 이상이어야 합니다.'; isLoading = false; }); return; } if (!mounted) return; context.go(dashboardRoutePath); } @override Widget build(BuildContext context) { final theme = ShadTheme.of(context); return Scaffold( body: Center( child: ConstrainedBox( constraints: const BoxConstraints(maxWidth: 460), child: Padding( padding: const EdgeInsets.all(24), child: ShadCard( title: Text('Superport v2 로그인', style: theme.textTheme.h3), description: Text( '사번 또는 이메일과 비밀번호를 입력하여 대시보드로 이동합니다.', style: theme.textTheme.muted, ), child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ ShadInput( controller: idController, placeholder: const Text('사번 또는 이메일'), autofillHints: const [AutofillHints.username], leading: const Icon(LucideIcons.user), ), const SizedBox(height: 16), ShadInput( controller: passwordController, placeholder: const Text('비밀번호'), obscureText: true, autofillHints: const [AutofillHints.password], leading: const Icon(LucideIcons.lock), ), const SizedBox(height: 12), Row( children: [ ShadSwitch( value: rememberMe, onChanged: (value) => setState(() => rememberMe = value), ), const SizedBox(width: 12), Text('자동 로그인', style: theme.textTheme.small), ], ), const SizedBox(height: 24), if (errorMessage != null) Padding( padding: const EdgeInsets.only(bottom: 12), child: Text( errorMessage!, style: theme.textTheme.small.copyWith( color: theme.colorScheme.destructive, ), ), ), ShadButton( onPressed: isLoading ? null : _handleSubmit, child: Row( mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.min, children: [ if (isLoading) ...[ const SizedBox( width: 16, height: 16, child: CircularProgressIndicator(strokeWidth: 2), ), const SizedBox(width: 8), ], const Text('로그인'), ], ), ), ], ), ), ), ), ), ); } }