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/core/utils/result.dart';
|
||||||
import 'package:tm_app/data/repositories/notification_repository.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/data/services/model/notification__response/notification_response_model.dart';
|
||||||
|
import 'package:tm_app/views/notification/strings/notification_strings.dart';
|
||||||
|
|
||||||
class NotificationViewModel with ChangeNotifier {
|
class NotificationViewModel with ChangeNotifier {
|
||||||
final NotificationsRepository _repository;
|
final NotificationsRepository _repository;
|
||||||
@@ -98,11 +99,15 @@ class NotificationViewModel with ChangeNotifier {
|
|||||||
|
|
||||||
final result = await _repository.markAllAsRead();
|
final result = await _repository.markAllAsRead();
|
||||||
|
|
||||||
|
if (!context.mounted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (result) {
|
switch (result) {
|
||||||
case Ok<Map<String, dynamic>>():
|
case Ok<Map<String, dynamic>>():
|
||||||
final response = result.value;
|
final response = result.value;
|
||||||
final success = response['success'] as bool? ?? false;
|
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 (success) {
|
||||||
if (_notificationResponseModel?.data?.notifications != null) {
|
if (_notificationResponseModel?.data?.notifications != null) {
|
||||||
@@ -118,21 +123,28 @@ class NotificationViewModel with ChangeNotifier {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
await getNotifications(page: currentPage, );
|
await getNotifications(page: currentPage);
|
||||||
await getUnreadNotifications();
|
await getUnreadNotifications();
|
||||||
|
|
||||||
|
if (context.mounted) {
|
||||||
// toast success
|
AppToast.success(
|
||||||
AppToast.success(context, 'All notifications marked as read.');
|
context,
|
||||||
|
NotificationStrings.allNotificationMarkedAsRead,
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
_errorMessage = message;
|
_errorMessage = message;
|
||||||
|
if (context.mounted) {
|
||||||
AppToast.error(context, message);
|
AppToast.error(context, message);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Error<Map<String, dynamic>>():
|
case Error<Map<String, dynamic>>():
|
||||||
_errorMessage = result.error.toString();
|
_errorMessage = result.error.toString();
|
||||||
|
if (context.mounted) {
|
||||||
AppToast.error(context, _errorMessage!);
|
AppToast.error(context, _errorMessage!);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,15 +158,15 @@ class NotificationViewModel with ChangeNotifier {
|
|||||||
final difference = now.difference(createdAt);
|
final difference = now.difference(createdAt);
|
||||||
|
|
||||||
if (difference.inMinutes < 1) {
|
if (difference.inMinutes < 1) {
|
||||||
return 'Now';
|
return NotificationStrings.now;
|
||||||
} else if (difference.inMinutes < 60) {
|
} else if (difference.inMinutes < 60) {
|
||||||
return '${difference.inMinutes} Min ';
|
return '${difference.inMinutes} ${NotificationStrings.min} ';
|
||||||
} else if (difference.inHours < 24) {
|
} else if (difference.inHours < 24) {
|
||||||
return '${difference.inHours} Hour ';
|
return '${difference.inHours} ${NotificationStrings.hour} ';
|
||||||
} else if (difference.inDays == 1) {
|
} else if (difference.inDays == 1) {
|
||||||
return 'Yesterday';
|
return NotificationStrings.yesterday;
|
||||||
} else {
|
} else {
|
||||||
return '${difference.inDays} days ago';
|
return '${difference.inDays} ${NotificationStrings.daysAgo}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ class _DesktopNotificationPageState extends State<DesktopNotificationPage>
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final viewModel = context.watch<NotificationViewModel>();
|
final viewModel = context.watch<NotificationViewModel>();
|
||||||
|
|
||||||
return Scaffold(
|
return SafeArea(
|
||||||
|
child: Scaffold(
|
||||||
backgroundColor: AppColors.backgroundColor,
|
backgroundColor: AppColors.backgroundColor,
|
||||||
body: Column(
|
body: Column(
|
||||||
children: [
|
children: [
|
||||||
@@ -197,6 +198,7 @@ class _DesktopNotificationPageState extends State<DesktopNotificationPage>
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,5 +11,14 @@ class NotificationStrings {
|
|||||||
static const String currentPage = 'currentPage';
|
static const String currentPage = 'currentPage';
|
||||||
static const String of = 'of';
|
static const String of = 'of';
|
||||||
static const String totalPages = 'totalPages';
|
static const String totalPages = 'totalPages';
|
||||||
|
static const String allNotificationMarkedAsRead = 'All notifications marked as read.';
|
||||||
|
static const String unknownResponse = 'Unknown response';
|
||||||
|
static const String now = 'Now';
|
||||||
|
static const String min = 'Min';
|
||||||
|
static const String hour = 'Hour';
|
||||||
|
static const String yesterday = 'Yesterday';
|
||||||
|
static const String daysAgo = 'days ago';
|
||||||
|
static const String reject = 'reject';
|
||||||
|
static const String info = 'info';
|
||||||
|
static const String noUnreadNotifications = 'No unread notifications';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import 'package:tm_app/core/theme/colors.dart';
|
|||||||
import 'package:tm_app/core/utils/size_config.dart';
|
import 'package:tm_app/core/utils/size_config.dart';
|
||||||
import 'package:tm_app/data/services/model/notification_data/notification_data.dart';
|
import 'package:tm_app/data/services/model/notification_data/notification_data.dart';
|
||||||
import 'package:tm_app/view_models/notification_view_model.dart';
|
import 'package:tm_app/view_models/notification_view_model.dart';
|
||||||
|
import 'package:tm_app/views/notification/strings/notification_strings.dart';
|
||||||
|
|
||||||
class NotificationCard extends StatelessWidget {
|
class NotificationCard extends StatelessWidget {
|
||||||
final NotificationItem notification;
|
final NotificationItem notification;
|
||||||
@@ -20,17 +21,17 @@ class NotificationCard extends StatelessWidget {
|
|||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.all(16.0),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color:
|
color:
|
||||||
notification.type == 'reject'
|
notification.type == NotificationStrings.reject
|
||||||
? AppColors.orange10
|
? AppColors.orange10
|
||||||
: notification.type == 'info'
|
: notification.type == NotificationStrings.info
|
||||||
? AppColors.primary10Light
|
? AppColors.primary10Light
|
||||||
: AppColors.green0,
|
: AppColors.green0,
|
||||||
borderRadius: BorderRadius.circular(4),
|
borderRadius: BorderRadius.circular(4),
|
||||||
border: Border.all(
|
border: Border.all(
|
||||||
color:
|
color:
|
||||||
notification.type! == 'reject'
|
notification.type! == NotificationStrings.reject
|
||||||
? AppColors.warningColor
|
? AppColors.warningColor
|
||||||
: notification.type == 'info' ? AppColors.primary20 : AppColors.green20,
|
: notification.type == NotificationStrings.info ? AppColors.primary20 : AppColors.green20,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
@@ -39,9 +40,9 @@ class NotificationCard extends StatelessWidget {
|
|||||||
Padding(
|
Padding(
|
||||||
padding: EdgeInsets.only(top: 3.0.h()),
|
padding: EdgeInsets.only(top: 3.0.h()),
|
||||||
child: SvgPicture.asset(
|
child: SvgPicture.asset(
|
||||||
notification.type! == 'info'
|
notification.type! == NotificationStrings.info
|
||||||
? AssetsManager.notification
|
? AssetsManager.notification
|
||||||
: notification.type! == 'reject'
|
: notification.type! == NotificationStrings.reject
|
||||||
? AssetsManager.danger
|
? AssetsManager.danger
|
||||||
: AssetsManager.tickCircle,
|
: AssetsManager.tickCircle,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:tm_app/core/utils/size_config.dart';
|
import 'package:tm_app/core/utils/size_config.dart';
|
||||||
import 'package:tm_app/view_models/notification_view_model.dart';
|
import 'package:tm_app/view_models/notification_view_model.dart';
|
||||||
|
import 'package:tm_app/views/notification/strings/notification_strings.dart';
|
||||||
|
|
||||||
import 'notification_card.dart';
|
import 'notification_card.dart';
|
||||||
|
|
||||||
@@ -21,7 +22,7 @@ class NotificationUnreadTab extends StatelessWidget {
|
|||||||
viewModel.unreadNotificationResponse?.data?.notifications ?? [];
|
viewModel.unreadNotificationResponse?.data?.notifications ?? [];
|
||||||
|
|
||||||
if (notifications.isEmpty) {
|
if (notifications.isEmpty) {
|
||||||
return const Center(child: Text('No unread notifications'));
|
return const Center(child: Text(NotificationStrings.noUnreadNotifications,));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
|
|||||||
Reference in New Issue
Block a user