- 화면마다 위젯/스타일만 담당하는 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 경로만 갱신하고 리팩터링은 보류
52 lines
1.7 KiB
Dart
52 lines
1.7 KiB
Dart
// 👨🏫 교사 회원가입 화면의 기능(서버 통신/상태) 담당 컨트롤러.
|
|
import 'dart:convert';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import '../config.dart';
|
|
|
|
class TeacherRegisterController extends ChangeNotifier {
|
|
bool _isLoading = false;
|
|
bool get isLoading => _isLoading;
|
|
|
|
/// (성공여부, 메시지)를 반환한다 — UI가 성공 시에만 이전 화면으로 돌아간다.
|
|
Future<(bool success, String message)> registerTeacher({
|
|
required String id,
|
|
required String password,
|
|
required String name,
|
|
required String secretCode,
|
|
}) async {
|
|
// 💡 테스트용 고유값 (실제 디바이스 UUID 연동 로직이 있다면 그걸 넣으세요)
|
|
final String dummyUuid = "TEACHER_PHONE_$id";
|
|
|
|
_isLoading = true;
|
|
notifyListeners();
|
|
try {
|
|
final response = await http.post(
|
|
Uri.parse('$baseUrl/api/users/register-teacher'),
|
|
headers: {"Content-Type": "application/json"},
|
|
body: jsonEncode({
|
|
"teacherId": id,
|
|
"password": password,
|
|
"name": name,
|
|
"secretCode": secretCode,
|
|
"deviceUuid": dummyUuid,
|
|
}),
|
|
);
|
|
|
|
final res = jsonDecode(response.body);
|
|
|
|
if (response.statusCode == 200 && res['status'] == 'success') {
|
|
return (true, '✅ ${res['message']}');
|
|
} else {
|
|
String errorMsg = res['detail'] ?? res['message'] ?? '회원가입에 실패했습니다.';
|
|
return (false, '❌ $errorMsg');
|
|
}
|
|
} catch (e) {
|
|
return (false, '❌ 서버와 통신에 실패했습니다.');
|
|
} finally {
|
|
_isLoading = false;
|
|
notifyListeners();
|
|
}
|
|
}
|
|
}
|