87 lines
4.2 KiB
Dart
87 lines
4.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:friendly_map/modules/app/app.dart';
|
|
|
|
import '../app_scope.dart';
|
|
import '../theme.dart';
|
|
import '../widgets/async_view.dart';
|
|
import '../widgets/common.dart';
|
|
|
|
/// 받은 요청: 새 기기로 다시 연결(승인/제명)과 새 친구(수락/거절).
|
|
class RequestsScreen extends StatelessWidget {
|
|
const RequestsScreen({super.key});
|
|
|
|
Future<void> _expel(BuildContext context, IncomingRequest r) async {
|
|
final name = r.known?.name ?? r.request.name;
|
|
final ok = await askConfirm(context, '$name님을 제명할까요?', '이 번호는 앞으로 인사·요청·대화를 영원히 보낼 수 없어요. 기존 대화 기록은 남아요.', ok: '제명');
|
|
if (!ok || !context.mounted) return;
|
|
await AppScope.of(context).app.blocks.expel(r.request.phone);
|
|
if (context.mounted) showNote(context, '$name님을 제명했어요.');
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final app = AppScope.of(context).app;
|
|
return Scaffold(
|
|
appBar: AppBar(title: const Text('받은 요청')),
|
|
body: AsyncView<List<IncomingRequest>>(
|
|
load: (a) => a.blocks.incoming(),
|
|
builder: (context, list) {
|
|
if (list.isEmpty) return const EmptyNote('받은 요청이 없어요.');
|
|
return ListView(padding: const EdgeInsets.only(top: 4, bottom: 32), children: [
|
|
for (final r in list)
|
|
Panel(
|
|
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
Row(children: [
|
|
Avatar(r.known?.name ?? r.request.name, size: 44),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
Text(r.known?.name ?? r.request.name, style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w700)),
|
|
Text(displayPhone(r.request.phone), style: const TextStyle(fontSize: 13, color: Pal.muted)),
|
|
]),
|
|
),
|
|
if (r.reconnect)
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
|
decoration: BoxDecoration(color: Pal.accent.withValues(alpha: 0.16), borderRadius: BorderRadius.circular(10)),
|
|
child: const Text('새 기기', style: TextStyle(fontSize: 11, fontWeight: FontWeight.w700, color: Pal.accent)),
|
|
),
|
|
]),
|
|
const SizedBox(height: 10),
|
|
Text(
|
|
r.reconnect
|
|
? '이미 아는 분이 새 폰에서 다시 연결을 청했어요. 본인이 맞으면 승인하세요. 이전 대화와 그룹은 그대로 이어져요.'
|
|
: '${r.request.name}님이 친구 요청을 보냈어요.',
|
|
style: const TextStyle(fontSize: 13, color: Pal.muted, height: 1.5),
|
|
),
|
|
const SizedBox(height: 12),
|
|
Row(children: [
|
|
Expanded(
|
|
child: r.reconnect
|
|
? OutlinedButton(
|
|
style: OutlinedButton.styleFrom(foregroundColor: Pal.danger),
|
|
onPressed: () => _expel(context, r),
|
|
child: const Text('제명'),
|
|
)
|
|
: OutlinedButton(onPressed: () => app.friends.decline(r.request.phone), child: const Text('거절')),
|
|
),
|
|
const SizedBox(width: 8),
|
|
Expanded(
|
|
child: FilledButton(
|
|
onPressed: () async {
|
|
await app.blocks.approve(r.request.phone);
|
|
if (context.mounted) showNote(context, r.reconnect ? '다시 연결했어요.' : '친구가 되었어요.');
|
|
},
|
|
child: Text(r.reconnect ? '승인' : '수락'),
|
|
),
|
|
),
|
|
]),
|
|
]),
|
|
),
|
|
]);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|