- 화면마다 위젯/스타일만 담당하는 UI 파일과, 서버통신/상태/파생로직만 담당하는 ChangeNotifier 컨트롤러 파일로 1:1 분리 (lib/screens/ -> lib/ui/ + lib/function/) - UI는 ListenableBuilder로 컨트롤러를 구독해서 재렌더링, 버튼은 컨트롤러 메서드만 호출 - 다이얼로그/스낵바 등 위젯 코드는 전부 UI 파일에 남기고, 컨트롤러는 결과값(성공여부+메시지) 또는 콜백으로만 UI와 통신 (BuildContext/Widget 의존성 없음) - 디자인/레이아웃은 기존과 완전히 동일하게 유지 (순수 코드 재배치) - change_password_screen.dart, debug_pocket_main.dart(미사용 파일)는 깨지지 않게 import 경로만 갱신하고 리팩터링은 보류
142 lines
4.9 KiB
Dart
142 lines
4.9 KiB
Dart
// 👨🏫 교사 회원가입 화면 (UI 전용). 서버 통신/상태는
|
|
// lib/function/teacher_register_controller.dart가 담당한다.
|
|
import 'package:flutter/material.dart';
|
|
import '../function/teacher_register_controller.dart';
|
|
|
|
class TeacherRegisterScreen extends StatefulWidget {
|
|
const TeacherRegisterScreen({super.key});
|
|
|
|
@override
|
|
State<TeacherRegisterScreen> createState() => _TeacherRegisterScreenState();
|
|
}
|
|
|
|
class _TeacherRegisterScreenState extends State<TeacherRegisterScreen> {
|
|
final TeacherRegisterController _controller = TeacherRegisterController();
|
|
final _idController = TextEditingController();
|
|
final _pwController = TextEditingController();
|
|
final _nameController = TextEditingController();
|
|
final _secretController = TextEditingController();
|
|
|
|
@override
|
|
void dispose() {
|
|
_controller.dispose();
|
|
_idController.dispose();
|
|
_pwController.dispose();
|
|
_nameController.dispose();
|
|
_secretController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
Future<void> _registerTeacher() async {
|
|
String id = _idController.text.trim();
|
|
String pw = _pwController.text.trim();
|
|
String name = _nameController.text.trim();
|
|
String secret = _secretController.text.trim();
|
|
|
|
if (id.isEmpty || pw.isEmpty || name.isEmpty || secret.isEmpty) {
|
|
ScaffoldMessenger.of(
|
|
context,
|
|
).showSnackBar(const SnackBar(content: Text('⚠️ 모든 빈칸을 입력해 주세요.')));
|
|
return;
|
|
}
|
|
|
|
final (success, message) = await _controller.registerTeacher(
|
|
id: id,
|
|
password: pw,
|
|
name: name,
|
|
secretCode: secret,
|
|
);
|
|
if (!mounted) return;
|
|
ScaffoldMessenger.of(
|
|
context,
|
|
).showSnackBar(SnackBar(content: Text(message)));
|
|
if (success) {
|
|
Navigator.pop(context); // 가입 성공 시 로그인 화면으로 복귀
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ListenableBuilder(
|
|
listenable: _controller,
|
|
builder: (context, _) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('교사 회원가입'),
|
|
backgroundColor: Colors.indigo,
|
|
foregroundColor: Colors.white,
|
|
),
|
|
body: SingleChildScrollView(
|
|
padding: const EdgeInsets.all(24.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const Text(
|
|
'👨🏫 교직원 전용 인증',
|
|
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
|
|
),
|
|
const SizedBox(height: 4),
|
|
const Text(
|
|
'학교에서 발급한 교사 가입 비밀코드가 필요합니다.',
|
|
style: TextStyle(color: Colors.grey),
|
|
),
|
|
const SizedBox(height: 24),
|
|
TextField(
|
|
controller: _secretController,
|
|
obscureText: true,
|
|
decoration: const InputDecoration(
|
|
labelText: '🔑 교사 인증 비밀코드 입력',
|
|
border: OutlineInputBorder(),
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
const Divider(),
|
|
const SizedBox(height: 16),
|
|
TextField(
|
|
controller: _idController,
|
|
decoration: const InputDecoration(
|
|
labelText: '교직원 번호 (ID로 사용)',
|
|
border: OutlineInputBorder(),
|
|
),
|
|
),
|
|
const SizedBox(height: 12),
|
|
TextField(
|
|
controller: _nameController,
|
|
decoration: const InputDecoration(
|
|
labelText: '선생님 성함',
|
|
border: OutlineInputBorder(),
|
|
),
|
|
),
|
|
const SizedBox(height: 12),
|
|
TextField(
|
|
controller: _pwController,
|
|
obscureText: true,
|
|
decoration: const InputDecoration(
|
|
labelText: '사용할 비밀번호 입력',
|
|
border: OutlineInputBorder(),
|
|
),
|
|
),
|
|
const SizedBox(height: 24),
|
|
SizedBox(
|
|
width: double.infinity,
|
|
height: 50,
|
|
child: ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Colors.indigo,
|
|
foregroundColor: Colors.white,
|
|
),
|
|
onPressed: _controller.isLoading ? null : _registerTeacher,
|
|
child: _controller.isLoading
|
|
? const CircularProgressIndicator(color: Colors.white)
|
|
: const Text('교사 계정 생성하기'),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|