// ๐Ÿ”‘ ๋น„๋ฐ€๋ฒˆํ˜ธ ๋ณ€๊ฒฝ ํ™”๋ฉด. (์ฐธ๊ณ : ํ˜„์žฌ ์•ฑ ์–ด๋””์„œ๋„ ์ด ํ™”๋ฉด์œผ๋กœ ์ด๋™ํ•˜๋Š” ๊ณณ์ด ์—†๋Š” ๋ฏธ์‚ฌ์šฉ ํ™”๋ฉด) import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:http/http.dart' as http; import '../config.dart'; import '../ui/login_screen.dart'; // ๐Ÿ’ก main.dart ํŒŒ์ผ์˜ ์ตœํ•˜๋‹จ(๋‹ค๋ฅธ ํด๋ž˜์Šค ์ค‘๊ด„ํ˜ธ ๋ฐ–)์— ๋ถ™์—ฌ๋„ฃ์œผ์„ธ์š”. class ChangePasswordScreen extends StatefulWidget { final String studentId; const ChangePasswordScreen({super.key, required this.studentId}); @override State createState() => _ChangePasswordScreenState(); } class _ChangePasswordScreenState extends State { final _pwController = TextEditingController(); bool _isLoading = false; Future _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( 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: Colors.indigo, foregroundColor: Colors.white, ), onPressed: _isLoading ? null : _updatePassword, child: _isLoading ? const CircularProgressIndicator(color: Colors.white) : const Text('๋ณ€๊ฒฝ ๋ฐ ์ ์šฉํ•˜๊ธฐ'), ), ), ], ), ), ); } }