feat: 优化前端 UI 与交互体验
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:go_router/go_router.dart';
|
||||
import '../../../../core/di/injection.dart';
|
||||
import '../../../../core/theme/design_tokens.dart';
|
||||
import '../../../../shared/widgets/app_loading_indicator.dart';
|
||||
import '../../../../shared/widgets/app_pull_refresh_feedback.dart';
|
||||
import '../../../../shared/widgets/page_header.dart';
|
||||
import '../../../../shared/widgets/toast/toast.dart';
|
||||
import '../../../../shared/widgets/toast/toast_type.dart';
|
||||
@@ -39,6 +40,7 @@ class _MessageInviteListScreenState extends State<MessageInviteListScreen> {
|
||||
List<MessageWithFriend> _unreadMessages = [];
|
||||
List<MessageWithFriend> _readMessages = [];
|
||||
bool _isLoading = false;
|
||||
bool _isPullRefreshing = false;
|
||||
int _activeTabIndex = 0;
|
||||
|
||||
@override
|
||||
@@ -51,12 +53,15 @@ class _MessageInviteListScreenState extends State<MessageInviteListScreen> {
|
||||
_loadMessages();
|
||||
}
|
||||
|
||||
Future<void> _loadMessages() async {
|
||||
if (_isLoading) {
|
||||
Future<void> _loadMessages({bool showPageLoader = true}) async {
|
||||
if (_isLoading || _isPullRefreshing) {
|
||||
return;
|
||||
}
|
||||
if (mounted) {
|
||||
setState(() => _isLoading = true);
|
||||
setState(() {
|
||||
_isLoading = showPageLoader;
|
||||
_isPullRefreshing = !showPageLoader;
|
||||
});
|
||||
}
|
||||
try {
|
||||
final results = await Future.wait([
|
||||
@@ -102,14 +107,22 @@ class _MessageInviteListScreenState extends State<MessageInviteListScreen> {
|
||||
_unreadMessages = unread;
|
||||
_readMessages = read;
|
||||
_isLoading = false;
|
||||
_isPullRefreshing = false;
|
||||
});
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
setState(() => _isLoading = false);
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
_isPullRefreshing = false;
|
||||
});
|
||||
Toast.show(context, '消息加载失败,请稍后重试', type: ToastType.error);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onRefreshMessages() async {
|
||||
await _loadMessages(showPageLoader: false);
|
||||
}
|
||||
|
||||
List<MessageWithFriend> _mapMessagesWithFriend(
|
||||
List<InboxMessageResponse> messages,
|
||||
Map<String, FriendRequestResponse?> requestMap,
|
||||
@@ -451,30 +464,37 @@ class _MessageInviteListScreenState extends State<MessageInviteListScreen> {
|
||||
List<MessageWithFriend> messages, {
|
||||
required bool isUnread,
|
||||
}) {
|
||||
return RefreshIndicator(
|
||||
onRefresh: _loadMessages,
|
||||
color: AppColors.blue500,
|
||||
child: ListView.builder(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
itemCount: messages.isEmpty ? 1 : messages.length,
|
||||
itemBuilder: (context, index) {
|
||||
if (messages.isEmpty) {
|
||||
return SizedBox(
|
||||
height: MediaQuery.sizeOf(context).height * 0.6,
|
||||
child: _buildEmptyState(isUnread: isUnread),
|
||||
);
|
||||
}
|
||||
final item = messages[index];
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: _MessageCard(
|
||||
item: item,
|
||||
onTap: () => _handleMessageTap(item),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
return Stack(
|
||||
children: [
|
||||
RefreshIndicator.noSpinner(
|
||||
onRefresh: _onRefreshMessages,
|
||||
child: ListView.builder(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
itemCount: messages.isEmpty ? 1 : messages.length,
|
||||
itemBuilder: (context, index) {
|
||||
if (messages.isEmpty) {
|
||||
return SizedBox(
|
||||
height: MediaQuery.sizeOf(context).height * 0.6,
|
||||
child: _buildEmptyState(isUnread: isUnread),
|
||||
);
|
||||
}
|
||||
final item = messages[index];
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: _MessageCard(
|
||||
item: item,
|
||||
onTap: () => _handleMessageTap(item),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.topCenter,
|
||||
child: AppPullRefreshFeedback(visible: _isPullRefreshing),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user