친구 신청·수락, 그룹 생성·초대(친구 목록에서 선택)·오늘 출석 현황 공유, 개인 연속 출석(스트릭) 달력, 관리자가 날짜별로 선물/이벤트를 등록하는 달력 관리 화면을 추가. 대시보드에 학생용 3개(친구/그룹 스터디/출석 달력) + 교사·관리자용 1개(출석 달력 관리) 타일을 배치. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
290 lines
11 KiB
Dart
290 lines
11 KiB
Dart
// 🧑🤝🧑 백품타 친구 화면 (UI 전용). "실시간 출석 현황"과 같은 패밀리룩을 따른다.
|
|
// 서버 통신/상태는 lib/function/friend_controller.dart가 담당한다.
|
|
import 'package:flutter/material.dart';
|
|
import '../function/friend_controller.dart';
|
|
import '../theme/app_palette.dart';
|
|
import 'app_notice.dart';
|
|
import 'title_pill.dart';
|
|
|
|
class FriendsScreen extends StatefulWidget {
|
|
final String studentId;
|
|
final String studentName;
|
|
|
|
const FriendsScreen({
|
|
super.key,
|
|
required this.studentId,
|
|
required this.studentName,
|
|
});
|
|
|
|
@override
|
|
State<FriendsScreen> createState() => _FriendsScreenState();
|
|
}
|
|
|
|
class _FriendsScreenState extends State<FriendsScreen> {
|
|
late final FriendController _controller;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_controller = FriendController(
|
|
studentId: widget.studentId,
|
|
studentName: widget.studentName,
|
|
);
|
|
_controller.init();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_controller.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
Future<void> _showAddFriendDialog() async {
|
|
final idController = TextEditingController();
|
|
final result = await showDialog<bool>(
|
|
context: context,
|
|
builder: (dialogContext) => AlertDialog(
|
|
title: const Text('친구 추가'),
|
|
content: TextField(
|
|
controller: idController,
|
|
keyboardType: TextInputType.number,
|
|
decoration: const InputDecoration(
|
|
labelText: '친구 학번',
|
|
border: OutlineInputBorder(),
|
|
),
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(dialogContext, false),
|
|
child: const Text('취소', style: TextStyle(color: Colors.grey)),
|
|
),
|
|
ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: AppPalette.ink,
|
|
foregroundColor: AppPalette.paper,
|
|
),
|
|
onPressed: () => Navigator.pop(dialogContext, true),
|
|
child: const Text('신청하기'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
if (result != true || idController.text.trim().isEmpty) return;
|
|
final (success, message) = await _controller.sendRequest(
|
|
idController.text.trim(),
|
|
);
|
|
if (!mounted) return;
|
|
AppNotice.show(
|
|
context,
|
|
message,
|
|
icon: success ? Icons.check_circle_rounded : Icons.error_outline_rounded,
|
|
);
|
|
}
|
|
|
|
Future<void> _respond(int requestId, bool accept) async {
|
|
final (_, message) = await _controller.respondRequest(requestId, accept);
|
|
if (!mounted) return;
|
|
AppNotice.show(context, message);
|
|
}
|
|
|
|
Future<void> _remove(String friendId) async {
|
|
final confirmed = await showDialog<bool>(
|
|
context: context,
|
|
builder: (dialogContext) => AlertDialog(
|
|
title: const Text('친구 삭제'),
|
|
content: const Text('이 친구를 삭제하시겠습니까?'),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(dialogContext, false),
|
|
child: const Text('취소', style: TextStyle(color: Colors.grey)),
|
|
),
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(dialogContext, true),
|
|
child: const Text('삭제', style: TextStyle(color: Colors.red)),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
if (confirmed != true) return;
|
|
final (_, message) = await _controller.removeFriend(friendId);
|
|
if (!mounted) return;
|
|
AppNotice.show(context, message);
|
|
}
|
|
|
|
Widget _sectionHeader(String title, {int? count}) {
|
|
return Row(
|
|
children: [
|
|
Container(
|
|
width: 4,
|
|
height: 16,
|
|
decoration: BoxDecoration(
|
|
color: AppPalette.ink,
|
|
borderRadius: BorderRadius.circular(2),
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
Text(
|
|
title,
|
|
style: const TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.bold,
|
|
color: AppPalette.ink,
|
|
),
|
|
),
|
|
if (count != null) ...[
|
|
const SizedBox(width: 6),
|
|
Text(
|
|
'$count명',
|
|
style: TextStyle(fontSize: 13, color: Colors.grey[500]),
|
|
),
|
|
],
|
|
],
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ListenableBuilder(
|
|
listenable: _controller,
|
|
builder: (context, _) {
|
|
return Scaffold(
|
|
backgroundColor: AppPalette.mist,
|
|
appBar: AppBar(
|
|
backgroundColor: Colors.transparent,
|
|
foregroundColor: AppPalette.ink,
|
|
elevation: 0,
|
|
),
|
|
floatingActionButton: FloatingActionButton.extended(
|
|
backgroundColor: AppPalette.ink,
|
|
foregroundColor: AppPalette.paper,
|
|
onPressed: _showAddFriendDialog,
|
|
icon: const Icon(Icons.person_add_rounded),
|
|
label: const Text('친구 추가'),
|
|
),
|
|
body: _controller.isLoading
|
|
? const Center(child: CircularProgressIndicator())
|
|
: RefreshIndicator(
|
|
onRefresh: _controller.refresh,
|
|
child: ListView(
|
|
padding: const EdgeInsets.fromLTRB(16, 0, 16, 90),
|
|
children: [
|
|
const Center(child: TitlePill('친구')),
|
|
const SizedBox(height: 20),
|
|
if (_controller.requests.isNotEmpty) ...[
|
|
_sectionHeader(
|
|
'받은 친구 신청',
|
|
count: _controller.requests.length,
|
|
),
|
|
const SizedBox(height: 10),
|
|
for (final r in _controller.requests)
|
|
Container(
|
|
margin: const EdgeInsets.only(bottom: 8),
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 16,
|
|
vertical: 12,
|
|
),
|
|
decoration: BoxDecoration(
|
|
color: AppPalette.paper,
|
|
borderRadius: BorderRadius.circular(16),
|
|
border: Border.all(color: AppPalette.sage),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
'${r['name']} (${r['studentId']})',
|
|
style: const TextStyle(
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
TextButton(
|
|
onPressed: () =>
|
|
_respond(r['requestId'] as int, false),
|
|
child: const Text(
|
|
'거절',
|
|
style: TextStyle(color: Colors.grey),
|
|
),
|
|
),
|
|
ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: AppPalette.ink,
|
|
foregroundColor: AppPalette.paper,
|
|
),
|
|
onPressed: () =>
|
|
_respond(r['requestId'] as int, true),
|
|
child: const Text('수락'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(height: 20),
|
|
],
|
|
_sectionHeader('내 친구', count: _controller.friends.length),
|
|
const SizedBox(height: 10),
|
|
if (_controller.friends.isEmpty)
|
|
const Padding(
|
|
padding: EdgeInsets.symmetric(vertical: 12),
|
|
child: Text(
|
|
'아직 친구가 없어요. 학번으로 친구를 추가해보세요.',
|
|
style: TextStyle(color: Colors.grey),
|
|
),
|
|
)
|
|
else
|
|
for (final f in _controller.friends)
|
|
Container(
|
|
margin: const EdgeInsets.only(bottom: 8),
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 16,
|
|
vertical: 12,
|
|
),
|
|
decoration: BoxDecoration(
|
|
color: AppPalette.paper,
|
|
borderRadius: BorderRadius.circular(16),
|
|
border: Border.all(color: AppPalette.sage),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.all(6),
|
|
decoration: BoxDecoration(
|
|
color: AppPalette.ink.withValues(
|
|
alpha: 0.06,
|
|
),
|
|
shape: BoxShape.circle,
|
|
),
|
|
child: const Icon(
|
|
Icons.person_rounded,
|
|
size: 16,
|
|
color: AppPalette.ink,
|
|
),
|
|
),
|
|
const SizedBox(width: 10),
|
|
Expanded(
|
|
child: Text(
|
|
'${f['name']} (${f['studentId']})',
|
|
style: const TextStyle(
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
IconButton(
|
|
icon: const Icon(
|
|
Icons.person_remove_outlined,
|
|
color: Colors.grey,
|
|
),
|
|
onPressed: () =>
|
|
_remove(f['studentId'] as String),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|