Fixed warning context and hard code strings in notificationModelView and some widgets
This commit is contained in:
@@ -3,6 +3,7 @@ import 'package:tm_app/core/utils/app_toast.dart';
|
||||
import 'package:tm_app/core/utils/result.dart';
|
||||
import 'package:tm_app/data/repositories/notification_repository.dart';
|
||||
import 'package:tm_app/data/services/model/notification__response/notification_response_model.dart';
|
||||
import 'package:tm_app/views/notification/strings/notification_strings.dart';
|
||||
|
||||
class NotificationViewModel with ChangeNotifier {
|
||||
final NotificationsRepository _repository;
|
||||
@@ -98,11 +99,15 @@ class NotificationViewModel with ChangeNotifier {
|
||||
|
||||
final result = await _repository.markAllAsRead();
|
||||
|
||||
if (!context.mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (result) {
|
||||
case Ok<Map<String, dynamic>>():
|
||||
final response = result.value;
|
||||
final success = response['success'] as bool? ?? false;
|
||||
final message = response['message'] as String? ?? 'Unknown response';
|
||||
final message = response['message'] as String? ?? NotificationStrings.unknownResponse;
|
||||
|
||||
if (success) {
|
||||
if (_notificationResponseModel?.data?.notifications != null) {
|
||||
@@ -118,21 +123,28 @@ class NotificationViewModel with ChangeNotifier {
|
||||
);
|
||||
}
|
||||
|
||||
await getNotifications(page: currentPage, );
|
||||
await getNotifications(page: currentPage);
|
||||
await getUnreadNotifications();
|
||||
|
||||
|
||||
// toast success
|
||||
AppToast.success(context, 'All notifications marked as read.');
|
||||
if (context.mounted) {
|
||||
AppToast.success(
|
||||
context,
|
||||
NotificationStrings.allNotificationMarkedAsRead,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
_errorMessage = message;
|
||||
AppToast.error(context, message);
|
||||
if (context.mounted) {
|
||||
AppToast.error(context, message);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Error<Map<String, dynamic>>():
|
||||
_errorMessage = result.error.toString();
|
||||
AppToast.error(context, _errorMessage!);
|
||||
if (context.mounted) {
|
||||
AppToast.error(context, _errorMessage!);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -146,15 +158,15 @@ class NotificationViewModel with ChangeNotifier {
|
||||
final difference = now.difference(createdAt);
|
||||
|
||||
if (difference.inMinutes < 1) {
|
||||
return 'Now';
|
||||
return NotificationStrings.now;
|
||||
} else if (difference.inMinutes < 60) {
|
||||
return '${difference.inMinutes} Min ';
|
||||
return '${difference.inMinutes} ${NotificationStrings.min} ';
|
||||
} else if (difference.inHours < 24) {
|
||||
return '${difference.inHours} Hour ';
|
||||
return '${difference.inHours} ${NotificationStrings.hour} ';
|
||||
} else if (difference.inDays == 1) {
|
||||
return 'Yesterday';
|
||||
return NotificationStrings.yesterday;
|
||||
} else {
|
||||
return '${difference.inDays} days ago';
|
||||
return '${difference.inDays} ${NotificationStrings.daysAgo}';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user