Files
school-attendance/lib/screens/change_password_screen.dart
T
sihooandClaude Sonnet 5 83c148186d 전역 테마를 팔레트로 교체 + 빠졌던 팝업 화면들 마무리
앱 전체 MaterialApp의 ThemeData가 여전히 primarySwatch: Colors.indigo
였던 게 진짜 원인이었음 — 개별 화면 색은 고쳤지만, 기본 위젯 스타일
(포커스 안 된 텍스트필드 밑줄, FilterChip 선택 색 등)은 전부 이
전역 테마를 그대로 따라가고 있어서 여전히 예전 색으로 보였음.
ColorScheme을 AppPalette 기준으로 재구성해 해결.

추가로 팔레트 작업에서 빠졌던 화면들도 마무리:
- teacher_register_screen.dart (교사 회원가입)
- nfc_tag_writer_screen.dart (NFC 태그 쓰기)
- change_password_screen.dart (미사용이지만 일관성을 위해 정리)
- teacher_attendance_page.dart의 주머니 번호 칩 색상

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-07 13:35:46 +09:00

112 lines
3.9 KiB
Dart

// 🔑 비밀번호 변경 화면. (참고: 현재 앱 어디서도 이 화면으로 이동하는 곳이 없는 미사용 화면)
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import '../config.dart';
import '../theme/app_palette.dart';
import '../ui/login_screen.dart';
// 💡 main.dart 파일의 최하단(다른 클래스 중괄호 밖)에 붙여넣으세요.
class ChangePasswordScreen extends StatefulWidget {
final String studentId;
const ChangePasswordScreen({super.key, required this.studentId});
@override
State<ChangePasswordScreen> createState() => _ChangePasswordScreenState();
}
class _ChangePasswordScreenState extends State<ChangePasswordScreen> {
final _pwController = TextEditingController();
bool _isLoading = false;
Future<void> _updatePassword() async {
String newPw = _pwController.text.trim();
if (newPw.isEmpty || newPw == "1234") {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('초기 비밀번호와 다른 안전한 비밀번호를 입력하세요.')),
);
return;
}
setState(() => _isLoading = true);
try {
final response = await http.post(
Uri.parse('$baseUrl/api/users/change-password'),
headers: {"Content-Type": "application/json"},
body: jsonEncode({"studentId": widget.studentId, "newPassword": newPw}),
);
final res = jsonDecode(response.body);
if (response.statusCode == 200 && res['status'] == 'success') {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('비밀번호 변경 완료! 다시 로그인해 주세요.')),
);
// 비밀번호를 바꿨으니 다시 로그인 화면으로 강제 이동
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => const LoginScreen()),
);
}
} catch (e) {
ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('통신 실패')));
} finally {
setState(() => _isLoading = false);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppPalette.mist,
body: Padding(
padding: const EdgeInsets.all(32.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'보안을 위해\n비밀번호를 변경해 주세요',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
height: 1.4,
),
),
const SizedBox(height: 8),
const Text(
'처음 로그인 시 초기 비밀번호(1234)를 반드시 변경해야 이용이 가능합니다.',
style: TextStyle(color: Colors.grey),
),
const SizedBox(height: 32),
TextField(
controller: _pwController,
obscureText: true,
decoration: const InputDecoration(
labelText: '새로운 비밀번호 입력',
border: OutlineInputBorder(),
),
),
const SizedBox(height: 16),
SizedBox(
width: double.infinity,
height: 50,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: AppPalette.ink,
foregroundColor: AppPalette.paper,
),
onPressed: _isLoading ? null : _updatePassword,
child: _isLoading
? const CircularProgressIndicator(color: Colors.white)
: const Text('변경 및 적용하기'),
),
),
],
),
),
);
}
}