2026-02-25 11:01:09 +08:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:go_router/go_router.dart';
|
2026-03-11 09:14:51 +08:00
|
|
|
import '../../../../core/di/injection.dart';
|
2026-02-25 11:01:09 +08:00
|
|
|
import '../../../../core/theme/design_tokens.dart';
|
2026-03-16 16:11:28 +08:00
|
|
|
import '../../../../shared/widgets/app_loading_indicator.dart';
|
2026-03-11 09:14:51 +08:00
|
|
|
import '../../../../shared/widgets/toast/index.dart';
|
2026-03-11 15:28:29 +08:00
|
|
|
import '../../../../shared/widgets/app_button.dart';
|
2026-02-25 11:01:09 +08:00
|
|
|
import '../../../../shared/widgets/page_header.dart' as widgets;
|
2026-03-11 09:14:51 +08:00
|
|
|
import '../../../friends/data/friends_api.dart';
|
|
|
|
|
import '../../../users/data/models/user_response.dart';
|
|
|
|
|
import '../../../users/data/users_api.dart';
|
2026-02-25 11:01:09 +08:00
|
|
|
|
|
|
|
|
class ContactsScreen extends StatefulWidget {
|
|
|
|
|
const ContactsScreen({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<ContactsScreen> createState() => _ContactsScreenState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _ContactsScreenState extends State<ContactsScreen> {
|
|
|
|
|
final _searchController = TextEditingController();
|
2026-03-11 09:14:51 +08:00
|
|
|
final _searchFocusNode = FocusNode();
|
2026-02-25 11:01:09 +08:00
|
|
|
|
2026-03-11 09:14:51 +08:00
|
|
|
List<FriendResponse> _friends = [];
|
2026-03-11 15:28:29 +08:00
|
|
|
List<FriendRequestResponse> _pendingRequests = [];
|
2026-03-11 09:14:51 +08:00
|
|
|
List<UserResponse> _searchResults = [];
|
|
|
|
|
bool _isLoading = true;
|
|
|
|
|
bool _isSearching = false;
|
|
|
|
|
bool _hasSearched = false;
|
2026-03-11 15:28:29 +08:00
|
|
|
String? _sendingRequestUserId;
|
2026-03-11 09:14:51 +08:00
|
|
|
final Set<String> _sentRequestIds = {};
|
|
|
|
|
Set<String> _friendIds = {};
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
_loadFriends();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _loadFriends() async {
|
|
|
|
|
try {
|
|
|
|
|
final friendsApi = sl<FriendsApi>();
|
|
|
|
|
final friends = await friendsApi.getFriends();
|
2026-03-11 15:28:29 +08:00
|
|
|
final outgoingRequests = await friendsApi.getOutgoingRequests();
|
|
|
|
|
final pendingRequests = outgoingRequests
|
|
|
|
|
.where((r) => r.status == 'pending')
|
|
|
|
|
.toList();
|
2026-03-11 09:14:51 +08:00
|
|
|
if (mounted) {
|
|
|
|
|
setState(() {
|
|
|
|
|
_friends = friends;
|
|
|
|
|
_friendIds = friends.map((f) => f.friend.id).toSet();
|
2026-03-11 15:28:29 +08:00
|
|
|
_sentRequestIds.addAll(outgoingRequests.map((r) => r.recipient.id));
|
|
|
|
|
_pendingRequests = pendingRequests;
|
2026-03-11 09:14:51 +08:00
|
|
|
_isLoading = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
if (mounted) {
|
|
|
|
|
setState(() {
|
|
|
|
|
_isLoading = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool _isValidEmail(String email) {
|
|
|
|
|
final emailRegex = RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,}$');
|
|
|
|
|
return emailRegex.hasMatch(email);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _onSearch() async {
|
|
|
|
|
final query = _searchController.text.trim();
|
|
|
|
|
|
|
|
|
|
if (query.isEmpty) {
|
|
|
|
|
Toast.show(context, '请输入邮箱地址', type: ToastType.warning);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!_isValidEmail(query)) {
|
|
|
|
|
Toast.show(context, '请输入有效的邮箱地址', type: ToastType.warning);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
|
_isSearching = true;
|
|
|
|
|
_searchResults = [];
|
|
|
|
|
_hasSearched = true;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
final usersApi = sl<UsersApi>();
|
|
|
|
|
final results = await usersApi.searchUsers(query);
|
|
|
|
|
|
|
|
|
|
if (mounted) {
|
|
|
|
|
setState(() {
|
|
|
|
|
_searchResults = results;
|
|
|
|
|
_isSearching = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
if (mounted) {
|
|
|
|
|
setState(() {
|
|
|
|
|
_isSearching = false;
|
|
|
|
|
});
|
|
|
|
|
Toast.show(context, '搜索失败,请稍后重试', type: ToastType.error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _sendFriendRequest(String targetUserId, String? content) async {
|
2026-03-11 15:28:29 +08:00
|
|
|
if (_sendingRequestUserId != null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-03-11 09:14:51 +08:00
|
|
|
try {
|
2026-03-11 15:28:29 +08:00
|
|
|
setState(() {
|
|
|
|
|
_sendingRequestUserId = targetUserId;
|
|
|
|
|
});
|
2026-03-11 09:14:51 +08:00
|
|
|
final friendsApi = sl<FriendsApi>();
|
2026-03-11 15:28:29 +08:00
|
|
|
await friendsApi.sendRequest(targetUserId, content: content);
|
2026-03-11 09:14:51 +08:00
|
|
|
|
|
|
|
|
if (mounted) {
|
|
|
|
|
setState(() {
|
|
|
|
|
_sentRequestIds.add(targetUserId);
|
2026-03-11 15:28:29 +08:00
|
|
|
_sendingRequestUserId = null;
|
2026-03-11 09:14:51 +08:00
|
|
|
});
|
|
|
|
|
Toast.show(context, '好友请求已发送', type: ToastType.success);
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
if (mounted) {
|
2026-03-11 15:28:29 +08:00
|
|
|
setState(() {
|
|
|
|
|
_sendingRequestUserId = null;
|
|
|
|
|
});
|
2026-03-11 09:14:51 +08:00
|
|
|
Toast.show(context, '发送失败,请稍后重试', type: ToastType.error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _showAddFriendDialog(UserResponse user) {
|
|
|
|
|
final controller = TextEditingController();
|
2026-03-11 15:28:29 +08:00
|
|
|
showModalBottomSheet<void>(
|
2026-03-11 09:14:51 +08:00
|
|
|
context: context,
|
2026-03-11 15:28:29 +08:00
|
|
|
isScrollControlled: true,
|
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
|
builder: (sheetContext) {
|
|
|
|
|
return Padding(
|
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
|
bottom: MediaQuery.of(sheetContext).viewInsets.bottom,
|
|
|
|
|
),
|
|
|
|
|
child: Container(
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
constraints: BoxConstraints(
|
|
|
|
|
maxHeight: MediaQuery.of(sheetContext).size.height * 0.7,
|
|
|
|
|
),
|
|
|
|
|
padding: const EdgeInsets.fromLTRB(
|
|
|
|
|
AppSpacing.xxl,
|
|
|
|
|
AppSpacing.lg,
|
|
|
|
|
AppSpacing.xxl,
|
|
|
|
|
AppSpacing.lg,
|
|
|
|
|
),
|
|
|
|
|
decoration: const BoxDecoration(
|
|
|
|
|
color: AppColors.white,
|
|
|
|
|
borderRadius: BorderRadius.vertical(
|
|
|
|
|
top: Radius.circular(AppRadius.xxl),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Center(
|
|
|
|
|
child: Container(
|
|
|
|
|
width: 40,
|
|
|
|
|
height: AppSpacing.xs,
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: AppColors.slate300,
|
|
|
|
|
borderRadius: BorderRadius.circular(AppRadius.full),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: AppSpacing.lg),
|
|
|
|
|
Text(
|
|
|
|
|
'添加 ${user.username}',
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontSize: 20,
|
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
color: AppColors.slate900,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: AppSpacing.sm),
|
|
|
|
|
const Text(
|
|
|
|
|
'发送一条验证信息,方便对方确认你的身份',
|
|
|
|
|
style: TextStyle(fontSize: 13, color: AppColors.slate500),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: AppSpacing.lg),
|
|
|
|
|
Container(
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: AppColors.slate50,
|
|
|
|
|
borderRadius: BorderRadius.circular(AppRadius.lg),
|
|
|
|
|
border: Border.all(color: AppColors.borderSecondary),
|
|
|
|
|
),
|
|
|
|
|
child: TextField(
|
|
|
|
|
controller: controller,
|
|
|
|
|
maxLines: 3,
|
|
|
|
|
minLines: 2,
|
|
|
|
|
maxLength: 200,
|
|
|
|
|
decoration: const InputDecoration(
|
|
|
|
|
hintText: '你好,我是...',
|
|
|
|
|
hintStyle: TextStyle(
|
|
|
|
|
fontSize: 13,
|
|
|
|
|
color: AppColors.slate400,
|
|
|
|
|
),
|
|
|
|
|
border: InputBorder.none,
|
|
|
|
|
contentPadding: EdgeInsets.all(AppSpacing.lg),
|
|
|
|
|
counterStyle: TextStyle(
|
|
|
|
|
fontSize: 11,
|
|
|
|
|
color: AppColors.slate400,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: AppSpacing.lg),
|
|
|
|
|
Row(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: AppButton(
|
|
|
|
|
text: '取消',
|
|
|
|
|
isOutlined: true,
|
|
|
|
|
onPressed: () => Navigator.pop(sheetContext),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: AppSpacing.md),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: _buildSendButton(
|
|
|
|
|
user.id,
|
|
|
|
|
controller,
|
|
|
|
|
sheetContext,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
SizedBox(
|
|
|
|
|
height:
|
|
|
|
|
MediaQuery.of(sheetContext).padding.bottom +
|
|
|
|
|
AppSpacing.sm,
|
|
|
|
|
),
|
|
|
|
|
],
|
2026-03-11 09:14:51 +08:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
2026-03-11 15:28:29 +08:00
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
2026-03-11 09:14:51 +08:00
|
|
|
}
|
2026-02-25 11:01:09 +08:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
_searchController.dispose();
|
2026-03-11 09:14:51 +08:00
|
|
|
_searchFocusNode.dispose();
|
2026-02-25 11:01:09 +08:00
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Scaffold(
|
2026-03-02 16:34:33 +08:00
|
|
|
backgroundColor: AppColors.surfaceSecondary,
|
2026-02-25 11:01:09 +08:00
|
|
|
body: SafeArea(
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
2026-02-25 11:02:33 +08:00
|
|
|
widgets.PageHeader(leading: widgets.BackButton()),
|
2026-02-25 11:01:09 +08:00
|
|
|
Expanded(
|
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
|
padding: const EdgeInsets.fromLTRB(20, 8, 20, 20),
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
_buildSearchRow(),
|
2026-03-11 09:14:51 +08:00
|
|
|
_buildSearchResults(),
|
2026-02-25 11:01:09 +08:00
|
|
|
const SizedBox(height: 16),
|
2026-03-11 15:28:29 +08:00
|
|
|
if (_pendingRequests.isNotEmpty) ...[
|
|
|
|
|
_buildSectionTitle('新的联系人'),
|
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
|
_buildPendingRequestCard(_pendingRequests),
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
],
|
2026-02-25 11:01:09 +08:00
|
|
|
_buildSectionTitle('全部联系人'),
|
|
|
|
|
const SizedBox(height: 8),
|
2026-03-11 09:14:51 +08:00
|
|
|
if (_isLoading)
|
|
|
|
|
const Center(
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: EdgeInsets.all(20),
|
2026-03-16 16:11:28 +08:00
|
|
|
child: AppLoadingIndicator(size: 22),
|
2026-03-11 09:14:51 +08:00
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
else if (_friends.isEmpty)
|
|
|
|
|
_buildEmptyState()
|
|
|
|
|
else
|
|
|
|
|
_buildContactCard(_friends),
|
2026-02-25 11:01:09 +08:00
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _buildSearchRow() {
|
|
|
|
|
return Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
2026-03-11 09:14:51 +08:00
|
|
|
child: Container(
|
|
|
|
|
height: 40,
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: AppColors.surfaceTertiary,
|
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
|
border: Border.all(color: const Color(0xFFE4EBF7)),
|
|
|
|
|
),
|
|
|
|
|
child: TextField(
|
|
|
|
|
controller: _searchController,
|
|
|
|
|
focusNode: _searchFocusNode,
|
|
|
|
|
decoration: const InputDecoration(
|
|
|
|
|
hintText: '输入邮箱搜索用户',
|
|
|
|
|
hintStyle: TextStyle(
|
|
|
|
|
fontSize: 13,
|
|
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
|
color: AppColors.slate400,
|
|
|
|
|
),
|
|
|
|
|
prefixIcon: Icon(
|
|
|
|
|
Icons.search,
|
|
|
|
|
size: 16,
|
|
|
|
|
color: AppColors.slate400,
|
|
|
|
|
),
|
|
|
|
|
border: InputBorder.none,
|
|
|
|
|
contentPadding: EdgeInsets.symmetric(
|
|
|
|
|
horizontal: 12,
|
|
|
|
|
vertical: 10,
|
|
|
|
|
),
|
2026-02-25 11:01:09 +08:00
|
|
|
),
|
2026-03-11 09:14:51 +08:00
|
|
|
style: const TextStyle(fontSize: 13),
|
|
|
|
|
keyboardType: TextInputType.emailAddress,
|
|
|
|
|
textInputAction: TextInputAction.search,
|
|
|
|
|
onSubmitted: (_) => _onSearch(),
|
|
|
|
|
onChanged: (value) {
|
|
|
|
|
if (value.isEmpty) {
|
|
|
|
|
setState(() {
|
|
|
|
|
_hasSearched = false;
|
|
|
|
|
_searchResults = [];
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
2026-02-25 11:01:09 +08:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 10),
|
|
|
|
|
GestureDetector(
|
2026-03-11 09:14:51 +08:00
|
|
|
onTap: _onSearch,
|
2026-02-25 11:01:09 +08:00
|
|
|
child: Container(
|
|
|
|
|
width: 40,
|
|
|
|
|
height: 40,
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: const Color(0xFFF1F7FF),
|
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
|
border: Border.all(color: const Color(0xFFD7E6FF)),
|
|
|
|
|
),
|
2026-03-11 09:14:51 +08:00
|
|
|
child: _isSearching
|
|
|
|
|
? const Padding(
|
|
|
|
|
padding: EdgeInsets.all(10),
|
2026-03-16 16:11:28 +08:00
|
|
|
child: AppLoadingIndicator(
|
|
|
|
|
size: 16,
|
|
|
|
|
strokeWidth: 2,
|
|
|
|
|
color: AppColors.blue500,
|
|
|
|
|
trackColor: AppColors.blue100,
|
|
|
|
|
withContainer: false,
|
|
|
|
|
),
|
2026-03-11 09:14:51 +08:00
|
|
|
)
|
|
|
|
|
: const Icon(Icons.search, size: 16, color: AppColors.blue500),
|
2026-02-25 11:01:09 +08:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 09:14:51 +08:00
|
|
|
Widget _buildSearchResults() {
|
|
|
|
|
if (!_hasSearched) {
|
|
|
|
|
return const SizedBox.shrink();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Container(
|
|
|
|
|
margin: const EdgeInsets.only(top: 8),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: AppColors.white,
|
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
|
boxShadow: [
|
|
|
|
|
BoxShadow(
|
|
|
|
|
color: Colors.black.withValues(alpha: 0.08),
|
|
|
|
|
blurRadius: 8,
|
|
|
|
|
offset: const Offset(0, 2),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
if (_isSearching)
|
|
|
|
|
Container(
|
|
|
|
|
padding: const EdgeInsets.all(20),
|
2026-03-16 16:11:28 +08:00
|
|
|
child: const Center(child: AppLoadingIndicator(size: 22)),
|
2026-03-11 09:14:51 +08:00
|
|
|
)
|
|
|
|
|
else if (_searchResults.isEmpty)
|
|
|
|
|
Container(
|
|
|
|
|
padding: const EdgeInsets.all(20),
|
|
|
|
|
child: const Center(
|
|
|
|
|
child: Text(
|
|
|
|
|
'未找到该用户',
|
|
|
|
|
style: TextStyle(fontSize: 14, color: AppColors.slate500),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
else
|
|
|
|
|
Column(
|
|
|
|
|
children: [
|
|
|
|
|
for (int i = 0; i < _searchResults.length; i++) ...[
|
|
|
|
|
_buildSearchResultItem(_searchResults[i]),
|
2026-03-11 15:28:29 +08:00
|
|
|
if (i < _searchResults.length - 1) _buildDivider(),
|
2026-03-11 09:14:51 +08:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _buildSearchResultItem(UserResponse user) {
|
|
|
|
|
final isFriend = _friendIds.contains(user.id);
|
|
|
|
|
final isSent = _sentRequestIds.contains(user.id);
|
|
|
|
|
final avatarColor = _getAvatarColor(user.id);
|
|
|
|
|
|
|
|
|
|
return Container(
|
|
|
|
|
height: 70,
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 14),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
2026-03-11 15:28:29 +08:00
|
|
|
_buildAvatar(user.avatarUrl, user.id, avatarColor),
|
2026-03-11 09:14:51 +08:00
|
|
|
const SizedBox(width: 12),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
user.username,
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontSize: 15,
|
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
color: AppColors.slate900,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
if (user.bio != null) ...[
|
|
|
|
|
const SizedBox(height: 2),
|
|
|
|
|
Text(
|
|
|
|
|
user.bio!,
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
color: AppColors.slate500,
|
|
|
|
|
),
|
|
|
|
|
maxLines: 1,
|
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
_buildAddButton(user.id, isFriend, isSent),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _buildAddButton(String userId, bool isFriend, bool isSent) {
|
|
|
|
|
if (isFriend) {
|
|
|
|
|
return Container(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: AppColors.slate300,
|
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
|
),
|
|
|
|
|
child: const Text(
|
|
|
|
|
'已是好友',
|
|
|
|
|
style: TextStyle(fontSize: 12, color: AppColors.slate500),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isSent) {
|
|
|
|
|
return Container(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: AppColors.slate300,
|
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
|
),
|
|
|
|
|
child: const Text(
|
|
|
|
|
'已发送',
|
|
|
|
|
style: TextStyle(fontSize: 12, color: AppColors.slate500),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return GestureDetector(
|
|
|
|
|
onTap: () {
|
|
|
|
|
final user = _searchResults.firstWhere((u) => u.id == userId);
|
|
|
|
|
_showAddFriendDialog(user);
|
|
|
|
|
},
|
|
|
|
|
child: Container(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: const Color(0xFFF1F7FF),
|
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
|
border: Border.all(color: const Color(0xFFD7E6FF)),
|
|
|
|
|
),
|
|
|
|
|
child: const Row(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
Icon(Icons.person_add, size: 14, color: AppColors.blue500),
|
|
|
|
|
SizedBox(width: 4),
|
|
|
|
|
Text(
|
|
|
|
|
'添加',
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
|
color: AppColors.blue500,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _buildEmptyState() {
|
|
|
|
|
return Container(
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
padding: const EdgeInsets.all(32),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: AppColors.white,
|
|
|
|
|
borderRadius: BorderRadius.circular(16),
|
|
|
|
|
border: Border.all(color: const Color(0xFFE3EAF6)),
|
|
|
|
|
),
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
const Icon(Icons.person_outline, size: 48, color: AppColors.slate400),
|
|
|
|
|
const SizedBox(height: 12),
|
|
|
|
|
const Text(
|
|
|
|
|
'暂无联系人',
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 15,
|
|
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
|
color: AppColors.slate500,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 4),
|
|
|
|
|
const Text(
|
|
|
|
|
'搜索邮箱添加好友开始聊天吧',
|
|
|
|
|
style: TextStyle(fontSize: 13, color: AppColors.slate400),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-25 11:01:09 +08:00
|
|
|
Widget _buildSectionTitle(String title) {
|
|
|
|
|
return Text(
|
|
|
|
|
title,
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontSize: 13,
|
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
color: AppColors.slate500,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 15:28:29 +08:00
|
|
|
Widget _buildPendingRequestCard(List<FriendRequestResponse> requests) {
|
|
|
|
|
return Container(
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: AppColors.white,
|
|
|
|
|
borderRadius: BorderRadius.circular(16),
|
|
|
|
|
border: Border.all(color: const Color(0xFFE3EAF6)),
|
|
|
|
|
),
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
for (int i = 0; i < requests.length; i++) ...[
|
|
|
|
|
_buildPendingRequestItem(requests[i]),
|
|
|
|
|
if (i < requests.length - 1) _buildDivider(),
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _buildPendingRequestItem(FriendRequestResponse request) {
|
|
|
|
|
final recipient = request.recipient;
|
|
|
|
|
final color = _getAvatarColor(recipient.id);
|
|
|
|
|
|
|
|
|
|
return Container(
|
|
|
|
|
height: 70,
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 14),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
_buildAvatar(recipient.avatarUrl, recipient.id, color),
|
|
|
|
|
const SizedBox(width: 12),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
recipient.username,
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontSize: 15,
|
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
color: AppColors.slate900,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 2),
|
|
|
|
|
const Text(
|
|
|
|
|
'等待对方确认',
|
|
|
|
|
style: TextStyle(fontSize: 12, color: AppColors.slate500),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 09:14:51 +08:00
|
|
|
Widget _buildContactCard(List<FriendResponse> friends) {
|
2026-02-25 11:01:09 +08:00
|
|
|
return Container(
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: AppColors.white,
|
|
|
|
|
borderRadius: BorderRadius.circular(16),
|
|
|
|
|
border: Border.all(color: const Color(0xFFE3EAF6)),
|
|
|
|
|
),
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
2026-03-11 09:14:51 +08:00
|
|
|
for (int i = 0; i < friends.length; i++) ...[
|
|
|
|
|
_buildContactItem(friends[i]),
|
2026-03-11 15:28:29 +08:00
|
|
|
if (i < friends.length - 1) _buildDivider(),
|
2026-02-25 11:01:09 +08:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 09:14:51 +08:00
|
|
|
Widget _buildContactItem(FriendResponse friend) {
|
|
|
|
|
final friendInfo = friend.friend;
|
|
|
|
|
final color = _getAvatarColor(friendInfo.id);
|
|
|
|
|
|
2026-02-25 11:01:09 +08:00
|
|
|
return GestureDetector(
|
2026-03-11 09:14:51 +08:00
|
|
|
onTap: () => context.push('/contacts/add?id=${friendInfo.id}'),
|
2026-02-25 11:01:09 +08:00
|
|
|
child: Container(
|
|
|
|
|
height: 70,
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 14),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
2026-03-11 15:28:29 +08:00
|
|
|
_buildAvatar(friendInfo.avatarUrl, friendInfo.id, color),
|
2026-02-25 11:01:09 +08:00
|
|
|
const SizedBox(width: 12),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
2026-03-11 09:14:51 +08:00
|
|
|
friendInfo.username,
|
2026-02-25 11:01:09 +08:00
|
|
|
style: const TextStyle(
|
|
|
|
|
fontSize: 15,
|
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
color: AppColors.slate900,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 09:14:51 +08:00
|
|
|
Color _getAvatarColor(String id) {
|
|
|
|
|
final colors = [
|
|
|
|
|
AppColors.blue500,
|
|
|
|
|
AppColors.violet600,
|
|
|
|
|
AppColors.blue600,
|
|
|
|
|
const Color(0xFF0EA5E9),
|
|
|
|
|
AppColors.violet500,
|
|
|
|
|
];
|
|
|
|
|
final index = id.hashCode.abs() % colors.length;
|
|
|
|
|
return colors[index];
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-25 11:01:09 +08:00
|
|
|
Color _getAvatarBackground(Color color) {
|
|
|
|
|
if (color == AppColors.blue500) return const Color(0xFFEEF4FF);
|
2026-03-02 16:34:33 +08:00
|
|
|
if (color == AppColors.violet600) return AppColors.surfaceInfoLight;
|
2026-02-25 11:01:09 +08:00
|
|
|
if (color == AppColors.blue600) return const Color(0xFFEDF5FF);
|
|
|
|
|
if (color == const Color(0xFF0EA5E9)) return const Color(0xFFF2F8FF);
|
|
|
|
|
if (color == AppColors.violet500) return const Color(0xFFF5F7FF);
|
|
|
|
|
return const Color(0xFFEEF4FF);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Color _getAvatarBorder(Color color) {
|
|
|
|
|
if (color == AppColors.blue500) return const Color(0xFFDDE8FB);
|
|
|
|
|
if (color == AppColors.violet600) return const Color(0xFFE2EAFB);
|
|
|
|
|
if (color == AppColors.blue600) return const Color(0xFFDCE9FB);
|
|
|
|
|
if (color == const Color(0xFF0EA5E9)) return const Color(0xFFDFEAFA);
|
|
|
|
|
if (color == AppColors.violet500) return const Color(0xFFE4E8FA);
|
|
|
|
|
return const Color(0xFFDDE8FB);
|
|
|
|
|
}
|
2026-03-11 15:28:29 +08:00
|
|
|
|
|
|
|
|
Widget _buildDivider() {
|
|
|
|
|
return Container(
|
|
|
|
|
height: 1,
|
|
|
|
|
margin: const EdgeInsets.symmetric(horizontal: 14),
|
|
|
|
|
color: const Color(0xFFEEF2F7),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _buildAvatar(String? avatarUrl, String userId, Color color) {
|
|
|
|
|
return Container(
|
|
|
|
|
width: 42,
|
|
|
|
|
height: 42,
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: _getAvatarBackground(color),
|
|
|
|
|
borderRadius: BorderRadius.circular(21),
|
|
|
|
|
border: Border.all(color: _getAvatarBorder(color)),
|
|
|
|
|
),
|
|
|
|
|
child: avatarUrl != null
|
|
|
|
|
? ClipRRect(
|
|
|
|
|
borderRadius: BorderRadius.circular(21),
|
|
|
|
|
child: Image.network(
|
|
|
|
|
avatarUrl,
|
|
|
|
|
width: 42,
|
|
|
|
|
height: 42,
|
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
|
errorBuilder: (context, error, stackTrace) => Icon(
|
|
|
|
|
Icons.person,
|
|
|
|
|
size: 18,
|
|
|
|
|
color: _getAvatarColor(userId),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: Icon(Icons.person, size: 18, color: _getAvatarColor(userId)),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _buildSendButton(
|
|
|
|
|
String userId,
|
|
|
|
|
TextEditingController controller,
|
|
|
|
|
BuildContext sheetContext,
|
|
|
|
|
) {
|
|
|
|
|
return SizedBox(
|
|
|
|
|
height: 44,
|
|
|
|
|
child: ElevatedButton(
|
|
|
|
|
onPressed: _sendingRequestUserId == userId
|
|
|
|
|
? null
|
|
|
|
|
: () async {
|
|
|
|
|
final content = controller.text.trim();
|
|
|
|
|
Navigator.pop(sheetContext);
|
|
|
|
|
await _sendFriendRequest(
|
|
|
|
|
userId,
|
|
|
|
|
content.isEmpty ? null : content,
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
|
|
backgroundColor: AppColors.blue500,
|
|
|
|
|
foregroundColor: AppColors.white,
|
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(AppRadius.sm),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
child: _sendingRequestUserId == userId
|
2026-03-16 16:11:28 +08:00
|
|
|
? const AppLoadingIndicator(
|
|
|
|
|
size: 16,
|
|
|
|
|
strokeWidth: 2,
|
|
|
|
|
color: AppColors.white,
|
|
|
|
|
trackColor: AppColors.blue300,
|
|
|
|
|
withContainer: false,
|
2026-03-11 15:28:29 +08:00
|
|
|
)
|
|
|
|
|
: const Text(
|
|
|
|
|
'发送',
|
|
|
|
|
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-02-25 11:01:09 +08:00
|
|
|
}
|