화면 타이틀, 스낵바/다이얼로그 메시지, 백그라운드 알림 문구 등 사용자에게 노출되는 텍스트에서 이모티콘을 전부 제거 (코드 주석은 대상 아님). 아이콘 위젯은 그대로 유지. main_dashboard.dart의 "계정 강제 삭제" 타일 아이콘 색상도 빨간색 대신 다른 타일과 동일한 검정(AppPalette.ink)으로 통일. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
101 lines
3.0 KiB
Dart
101 lines
3.0 KiB
Dart
// 📋 선생님용 "스마트기기 반출 대장" 화면의 기능(서버 통신/상태) 담당 컨트롤러.
|
|
import 'dart:async';
|
|
import 'dart:convert';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import '../config.dart';
|
|
|
|
class DeviceCheckoutLedgerController extends ChangeNotifier {
|
|
List<dynamic> _requests = [];
|
|
bool _isLoading = true;
|
|
bool _isWorking = false;
|
|
Timer? _timer;
|
|
bool _disposed = false;
|
|
|
|
List<dynamic> get requests => _requests;
|
|
bool get isLoading => _isLoading;
|
|
bool get isWorking => _isWorking;
|
|
|
|
void _safeNotify() {
|
|
if (!_disposed) notifyListeners();
|
|
}
|
|
|
|
void init() {
|
|
fetchAll();
|
|
_timer = Timer.periodic(const Duration(seconds: 5), (_) => fetchAll());
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_disposed = true;
|
|
_timer?.cancel();
|
|
super.dispose();
|
|
}
|
|
|
|
Future<void> fetchAll() async {
|
|
try {
|
|
final response = await http.get(
|
|
Uri.parse('$baseUrl/api/device-checkout/list'),
|
|
);
|
|
if (response.statusCode == 200) {
|
|
final data = jsonDecode(utf8.decode(response.bodyBytes));
|
|
_requests = data['requests'] ?? [];
|
|
}
|
|
} catch (_) {
|
|
// 새로고침 실패는 조용히 무시하고 마지막으로 받아온 목록을 유지한다.
|
|
} finally {
|
|
_isLoading = false;
|
|
_safeNotify();
|
|
}
|
|
}
|
|
|
|
// ✅ 승인 시 승인한 선생님 계정을 함께 보낸다 (대장에 "OOO 선생님이 허용했습니다" 표시 +
|
|
// 미반납 알림을 그 선생님에게만 보내기 위함).
|
|
Future<(bool success, String message)> approve(
|
|
int requestId, {
|
|
required String teacherId,
|
|
required String teacherName,
|
|
}) async {
|
|
return _postAction('/api/device-checkout/approve', {
|
|
"requestId": requestId,
|
|
"teacherId": teacherId,
|
|
"teacherName": teacherName,
|
|
});
|
|
}
|
|
|
|
Future<(bool success, String message)> reject(int requestId) async {
|
|
return _postAction('/api/device-checkout/reject', {"requestId": requestId});
|
|
}
|
|
|
|
// 🖐️ [하드웨어 자동 감지 전까지 임시] 선생님이 기기를 실제로 돌려받았을 때 누르는 버튼.
|
|
Future<(bool success, String message)> confirmReturn(int requestId) async {
|
|
return _postAction('/api/device-checkout/return', {"requestId": requestId});
|
|
}
|
|
|
|
Future<(bool success, String message)> _postAction(
|
|
String path,
|
|
Map<String, dynamic> body,
|
|
) async {
|
|
_isWorking = true;
|
|
_safeNotify();
|
|
try {
|
|
final response = await http.post(
|
|
Uri.parse('$baseUrl$path'),
|
|
headers: {"Content-Type": "application/json"},
|
|
body: jsonEncode(body),
|
|
);
|
|
final result = jsonDecode(utf8.decode(response.bodyBytes));
|
|
if (response.statusCode == 200 && result['status'] == 'success') {
|
|
await fetchAll();
|
|
return (true, '${result['message'] ?? '처리되었습니다.'}');
|
|
}
|
|
return (false, '${result['message'] ?? '처리 실패'}');
|
|
} catch (e) {
|
|
return (false, '네트워크 에러: $e');
|
|
} finally {
|
|
_isWorking = false;
|
|
_safeNotify();
|
|
}
|
|
}
|
|
}
|