Fixed loading bug in notification mobile
This commit is contained in:
@@ -39,9 +39,16 @@ class NotificationViewModel with ChangeNotifier {
|
||||
_unreadNotificationResponse;
|
||||
bool get isUnreadLoading => _isUnreadLoading;
|
||||
|
||||
bool _isMoreLoading = false;
|
||||
bool get isMoreLoading => _isMoreLoading;
|
||||
|
||||
/// Fetch notifications
|
||||
Future<void> getNotifications({int page = 1, bool isMobile = false}) async {
|
||||
_isLoading = true;
|
||||
if (isMobile && page > 1) {
|
||||
_isMoreLoading = true; // 👈 لودینگ فقط برای پیج بعدی
|
||||
} else {
|
||||
_isLoading = true; // 👈 لودینگ عادی (اولین بار یا رفرش)
|
||||
}
|
||||
notifyListeners();
|
||||
|
||||
final int offset = _pageSize * page;
|
||||
@@ -80,6 +87,7 @@ class NotificationViewModel with ChangeNotifier {
|
||||
}
|
||||
|
||||
_isLoading = false;
|
||||
_isMoreLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@@ -107,7 +115,9 @@ class NotificationViewModel with ChangeNotifier {
|
||||
case Ok<Map<String, dynamic>>():
|
||||
final response = result.value;
|
||||
final success = response['success'] as bool? ?? false;
|
||||
final message = response['message'] as String? ?? NotificationStrings.unknownResponse;
|
||||
final message =
|
||||
response['message'] as String? ??
|
||||
NotificationStrings.unknownResponse;
|
||||
|
||||
if (success) {
|
||||
if (_notificationResponseModel?.data?.notifications != null) {
|
||||
|
||||
@@ -112,7 +112,17 @@ class _MobileNotificationPageState extends State<MobileNotificationPage>
|
||||
],
|
||||
),
|
||||
),
|
||||
if (viewModel.isLoading) ...[
|
||||
if (viewModel.isMoreLoading) ...[
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(color: AppColors.secondary50),
|
||||
),
|
||||
),
|
||||
],
|
||||
if (viewModel.isLoading &&
|
||||
(viewModel.notificationResponse?.data?.notifications?.isEmpty ??
|
||||
true)) ...[
|
||||
const Spacer(),
|
||||
const Center(
|
||||
child: CircularProgressIndicator(color: AppColors.secondary50),
|
||||
|
||||
Reference in New Issue
Block a user