feat(apps): 重构 UI 架构为 presentation 层并新增 l10n 国际化支持
This commit is contained in:
@@ -0,0 +1,205 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../../../../core/l10n/l10n.dart';
|
||||
import '../../../../core/theme/design_tokens.dart';
|
||||
import '../../../../shared/widgets/back_title_page_header.dart';
|
||||
import '../../../../shared/widgets/app_input.dart';
|
||||
import '../../../../shared/widgets/link_button.dart';
|
||||
import '../../../../shared/widgets/toast/toast.dart';
|
||||
import '../../../../shared/widgets/toast/toast_type.dart';
|
||||
|
||||
class AddContactScreen extends StatefulWidget {
|
||||
final String? contactId;
|
||||
|
||||
const AddContactScreen({super.key, this.contactId});
|
||||
|
||||
@override
|
||||
State<AddContactScreen> createState() => _AddContactScreenState();
|
||||
}
|
||||
|
||||
class _AddContactScreenState extends State<AddContactScreen> {
|
||||
final _nameController = TextEditingController();
|
||||
final _phoneController = TextEditingController();
|
||||
final _remarkController = TextEditingController();
|
||||
|
||||
bool get isEditing => widget.contactId != null;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_nameController.dispose();
|
||||
_phoneController.dispose();
|
||||
_remarkController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.surfaceSecondary,
|
||||
resizeToAvoidBottomInset: false,
|
||||
body: SafeArea(
|
||||
maintainBottomViewPadding: true,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
BackTitlePageHeader(
|
||||
title: isEditing
|
||||
? context.l10n.contactEditTitle
|
||||
: context.l10n.contactAddTitle,
|
||||
onBack: () => context.pop(),
|
||||
trailing: _buildConfirmButton(),
|
||||
),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(20, 8, 20, 20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_buildAvatarSection(),
|
||||
const SizedBox(height: 14),
|
||||
_buildFormCard(),
|
||||
if (isEditing) ...[
|
||||
const SizedBox(height: 14),
|
||||
_buildDeleteRow(),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildConfirmButton() {
|
||||
return SizedBox(
|
||||
width: AppSpacing.xxl * 2,
|
||||
height: AppSpacing.xxl * 2,
|
||||
child: TextButton(
|
||||
onPressed: _handleConfirm,
|
||||
style: TextButton.styleFrom(
|
||||
padding: const EdgeInsets.all(AppSpacing.none),
|
||||
backgroundColor: AppColors.surfaceInfo,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(AppRadius.full),
|
||||
side: const BorderSide(color: AppColors.borderQuaternary),
|
||||
),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.check,
|
||||
size: AppSpacing.lg,
|
||||
color: AppColors.blue600,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAvatarSection() {
|
||||
return Center(
|
||||
child: Container(
|
||||
width: 72,
|
||||
height: 72,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceInfoLight,
|
||||
borderRadius: BorderRadius.circular(36),
|
||||
border: Border.all(color: Colors.transparent),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.person_outline,
|
||||
size: 24,
|
||||
color: AppColors.slate400,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFormCard() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(14),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: AppColors.messageCardBorder),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
AppInput(
|
||||
label: context.l10n.contactNickname,
|
||||
hint: context.l10n.contactNicknameHint,
|
||||
controller: _nameController,
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
AppInput(
|
||||
label: context.l10n.contactPhone,
|
||||
hint: context.l10n.contactPhoneHint,
|
||||
controller: _phoneController,
|
||||
keyboardType: TextInputType.phone,
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
AppInput(
|
||||
label: context.l10n.contactRemark,
|
||||
hint: context.l10n.contactRemarkHint,
|
||||
controller: _remarkController,
|
||||
maxLines: 3,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDeleteRow() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: AppSpacing.sm),
|
||||
child: LinkButton(
|
||||
text: context.l10n.contactDelete,
|
||||
onTap: _handleDelete,
|
||||
foregroundColor: AppColors.red600,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _handleConfirm() {
|
||||
final name = _nameController.text.trim();
|
||||
final phone = _phoneController.text.trim();
|
||||
|
||||
if (name.isEmpty || phone.isEmpty) {
|
||||
Toast.show(
|
||||
context,
|
||||
context.l10n.contactFillRequired,
|
||||
type: ToastType.warning,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Implement save logic
|
||||
context.pop();
|
||||
}
|
||||
|
||||
void _handleDelete() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text(context.l10n.contactDeleteConfirmTitle),
|
||||
content: Text(context.l10n.contactDeleteConfirmMessage),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text(context.l10n.commonCancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
// TODO: Implement delete logic
|
||||
context.pop();
|
||||
},
|
||||
child: Text(
|
||||
context.l10n.commonDelete,
|
||||
style: const TextStyle(color: AppColors.red600),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,813 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../../../../app/di/injection.dart';
|
||||
import '../../../../core/l10n/l10n.dart';
|
||||
import '../../../../core/theme/design_tokens.dart';
|
||||
import '../../../../shared/widgets/app_loading_indicator.dart';
|
||||
import '../../../../shared/widgets/toast/index.dart';
|
||||
import '../../../../shared/widgets/app_button.dart';
|
||||
import '../../../../shared/widgets/back_title_page_header.dart';
|
||||
import '../../../contacts/data/friends_api.dart';
|
||||
import '../../../contacts/data/users/models/user_response.dart';
|
||||
import '../../../contacts/data/users/users_api.dart';
|
||||
|
||||
class ContactsScreen extends StatefulWidget {
|
||||
const ContactsScreen({super.key});
|
||||
|
||||
@override
|
||||
State<ContactsScreen> createState() => _ContactsScreenState();
|
||||
}
|
||||
|
||||
class _ContactsScreenState extends State<ContactsScreen> {
|
||||
final _searchController = TextEditingController();
|
||||
final _searchFocusNode = FocusNode();
|
||||
|
||||
List<FriendResponse> _friends = [];
|
||||
List<FriendRequestResponse> _pendingRequests = [];
|
||||
List<UserResponse> _searchResults = [];
|
||||
bool _isLoading = true;
|
||||
bool _isSearching = false;
|
||||
bool _hasSearched = false;
|
||||
String? _sendingRequestUserId;
|
||||
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();
|
||||
final outgoingRequests = await friendsApi.getOutgoingRequests();
|
||||
final pendingRequests = outgoingRequests
|
||||
.where((r) => r.status == 'pending')
|
||||
.toList();
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_friends = friends;
|
||||
_friendIds = friends.map((f) => f.friend.id).toSet();
|
||||
_sentRequestIds.addAll(outgoingRequests.map((r) => r.recipient.id));
|
||||
_pendingRequests = pendingRequests;
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onSearch() async {
|
||||
final query = _searchController.text.trim();
|
||||
|
||||
if (query.isEmpty) {
|
||||
Toast.show(
|
||||
context,
|
||||
context.l10n.contactsSearchEmptyQuery,
|
||||
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,
|
||||
context.l10n.contactsSearchFailed,
|
||||
type: ToastType.error,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _sendFriendRequest(String targetUserId, String? content) async {
|
||||
if (_sendingRequestUserId != null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
setState(() {
|
||||
_sendingRequestUserId = targetUserId;
|
||||
});
|
||||
final friendsApi = sl<FriendsApi>();
|
||||
await friendsApi.sendRequest(targetUserId, content: content);
|
||||
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_sentRequestIds.add(targetUserId);
|
||||
_sendingRequestUserId = null;
|
||||
});
|
||||
Toast.show(
|
||||
context,
|
||||
context.l10n.contactsFriendRequestSent,
|
||||
type: ToastType.success,
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_sendingRequestUserId = null;
|
||||
});
|
||||
Toast.show(
|
||||
context,
|
||||
context.l10n.contactsSendFailed,
|
||||
type: ToastType.error,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _showAddFriendDialog(UserResponse user) {
|
||||
final controller = TextEditingController();
|
||||
showModalBottomSheet<void>(
|
||||
context: context,
|
||||
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(
|
||||
context.l10n.contactsAddSheetTitle(user.username),
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate900,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
Text(
|
||||
context.l10n.contactsAddSheetDesc,
|
||||
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: InputDecoration(
|
||||
hintText: context.l10n.contactsAddSheetMessageHint,
|
||||
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: context.l10n.commonCancel,
|
||||
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,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_searchController.dispose();
|
||||
_searchFocusNode.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.surfaceSecondary,
|
||||
resizeToAvoidBottomInset: false,
|
||||
body: SafeArea(
|
||||
maintainBottomViewPadding: true,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
BackTitlePageHeader(
|
||||
title: context.l10n.contactsTitle,
|
||||
onBack: () => context.pop(),
|
||||
),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(20, 8, 20, 20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildSearchRow(),
|
||||
_buildSearchResults(),
|
||||
const SizedBox(height: 16),
|
||||
if (_pendingRequests.isNotEmpty) ...[
|
||||
_buildSectionTitle(context.l10n.contactsSectionNew),
|
||||
const SizedBox(height: 8),
|
||||
_buildPendingRequestCard(_pendingRequests),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
_buildSectionTitle(context.l10n.contactsSectionAll),
|
||||
const SizedBox(height: 8),
|
||||
if (_isLoading)
|
||||
const Center(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(20),
|
||||
child: AppLoadingIndicator(size: 22),
|
||||
),
|
||||
)
|
||||
else if (_friends.isEmpty)
|
||||
_buildEmptyState()
|
||||
else
|
||||
_buildContactCard(_friends),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSearchRow() {
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(
|
||||
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: InputDecoration(
|
||||
hintText: context.l10n.contactsSearchHint,
|
||||
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,
|
||||
),
|
||||
),
|
||||
style: const TextStyle(fontSize: 13),
|
||||
keyboardType: TextInputType.text,
|
||||
textInputAction: TextInputAction.search,
|
||||
onSubmitted: (_) => _onSearch(),
|
||||
onChanged: (value) {
|
||||
if (value.isEmpty) {
|
||||
setState(() {
|
||||
_hasSearched = false;
|
||||
_searchResults = [];
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
GestureDetector(
|
||||
onTap: _onSearch,
|
||||
child: Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF1F7FF),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: const Color(0xFFD7E6FF)),
|
||||
),
|
||||
child: _isSearching
|
||||
? const Padding(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: AppLoadingIndicator(
|
||||
size: 16,
|
||||
strokeWidth: 2,
|
||||
color: AppColors.blue500,
|
||||
trackColor: AppColors.blue100,
|
||||
withContainer: false,
|
||||
),
|
||||
)
|
||||
: const Icon(Icons.search, size: 16, color: AppColors.blue500),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
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),
|
||||
child: const Center(child: AppLoadingIndicator(size: 22)),
|
||||
)
|
||||
else if (_searchResults.isEmpty)
|
||||
Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Center(
|
||||
child: Text(
|
||||
context.l10n.contactsSearchNoUser,
|
||||
style: TextStyle(fontSize: 14, color: AppColors.slate500),
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
Column(
|
||||
children: [
|
||||
for (int i = 0; i < _searchResults.length; i++) ...[
|
||||
_buildSearchResultItem(_searchResults[i]),
|
||||
if (i < _searchResults.length - 1) _buildDivider(),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
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: [
|
||||
_buildAvatar(user.avatarUrl, user.id, avatarColor),
|
||||
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: Text(
|
||||
context.l10n.contactsStatusAlreadyFriend,
|
||||
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: Text(
|
||||
context.l10n.contactsStatusSent,
|
||||
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: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.person_add, size: 14, color: AppColors.blue500),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
context.l10n.contactsAdd,
|
||||
style: const 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),
|
||||
Text(
|
||||
context.l10n.contactsEmptyTitle,
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.slate500,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
context.l10n.contactsEmptyDesc,
|
||||
style: TextStyle(fontSize: 13, color: AppColors.slate400),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSectionTitle(String title) {
|
||||
return Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate500,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
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),
|
||||
Text(
|
||||
context.l10n.contactsPendingConfirm,
|
||||
style: TextStyle(fontSize: 12, color: AppColors.slate500),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildContactCard(List<FriendResponse> friends) {
|
||||
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 < friends.length; i++) ...[
|
||||
_buildContactItem(friends[i]),
|
||||
if (i < friends.length - 1) _buildDivider(),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildContactItem(FriendResponse friend) {
|
||||
final friendInfo = friend.friend;
|
||||
final color = _getAvatarColor(friendInfo.id);
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () => context.push('/contacts/add?id=${friendInfo.id}'),
|
||||
child: Container(
|
||||
height: 70,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14),
|
||||
child: Row(
|
||||
children: [
|
||||
_buildAvatar(friendInfo.avatarUrl, friendInfo.id, color),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
friendInfo.username,
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.slate900,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
Color _getAvatarBackground(Color color) {
|
||||
if (color == AppColors.blue500) return const Color(0xFFEEF4FF);
|
||||
if (color == AppColors.violet600) return AppColors.surfaceInfoLight;
|
||||
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);
|
||||
}
|
||||
|
||||
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
|
||||
? const AppLoadingIndicator(
|
||||
size: 16,
|
||||
strokeWidth: 2,
|
||||
color: AppColors.white,
|
||||
trackColor: AppColors.blue300,
|
||||
withContainer: false,
|
||||
)
|
||||
: Text(
|
||||
context.l10n.contactsSend,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user