Merge pull request 'safearea' (#160) from safearea into main

Reviewed-on: https://repo.ravanertebat.com/TM/tm_app/pulls/160
This commit is contained in:
a.ghabeli
2025-09-24 13:51:47 +03:30
29 changed files with 1267 additions and 1178 deletions
+33 -11
View File
@@ -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;
@@ -38,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;
@@ -79,6 +87,7 @@ class NotificationViewModel with ChangeNotifier {
}
_isLoading = false;
_isMoreLoading = false;
notifyListeners();
}
@@ -98,11 +107,17 @@ 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 +133,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;
if (context.mounted) {
AppToast.error(context, message);
}
}
break;
case Error<Map<String, dynamic>>():
_errorMessage = result.error.toString();
if (context.mounted) {
AppToast.error(context, _errorMessage!);
}
break;
}
@@ -146,15 +168,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}';
}
}
@@ -18,7 +18,8 @@ class CompletionOfDocumentsMobilePage extends StatelessWidget {
context: context,
title: CompletionOfDocumentsStrings.completionOfDocuments,
),
body: SingleChildScrollView(
body: SafeArea(
child: SingleChildScrollView(
padding: EdgeInsets.symmetric(horizontal: 16.0.w(), vertical: 12.0.h()),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
@@ -229,6 +230,7 @@ class CompletionOfDocumentsMobilePage extends StatelessWidget {
],
),
),
),
);
}
@@ -96,7 +96,8 @@ class _TenderDetailDesktopPageState extends State<TenderDetailDesktopPage> {
return const Center(child: Text(TenderDetailsStrings.tenderNoData));
}
return Column(
return SafeArea(
child: Column(
children: [
const DesktopNavigationWidget(
currentIndex: 1, // Home index
@@ -134,6 +135,7 @@ class _TenderDetailDesktopPageState extends State<TenderDetailDesktopPage> {
),
),
],
),
);
},
),
@@ -102,7 +102,8 @@ class _TenderDetailMobilePageState extends State<TenderDetailMobilePage> {
);
}
return SingleChildScrollView(
return SafeArea(
child: SingleChildScrollView(
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: 16.0.w(),
@@ -119,6 +120,7 @@ class _TenderDetailMobilePageState extends State<TenderDetailMobilePage> {
],
),
),
),
);
},
),
@@ -104,7 +104,8 @@ class _TenderDetailTabletPageState extends State<TenderDetailTabletPage> {
if (detail == null) {
return const Center(child: Text(TenderDetailsStrings.tenderNoData));
}
return SingleChildScrollView(
return SafeArea(
child: SingleChildScrollView(
child: Center(
child: SizedBox(
width: 768,
@@ -128,6 +129,7 @@ class _TenderDetailTabletPageState extends State<TenderDetailTabletPage> {
),
),
),
),
);
},
),
@@ -23,7 +23,8 @@ class FinalCompletionOfDocumentsScreen extends StatelessWidget {
return Scaffold(
body: Consumer<FinalCompletionOfDocumentsViewModel>(
builder:
(context, viewModel, child) => Column(
(context, viewModel, child) => SafeArea(
child: Column(
children: [
const DesktopNavigationWidget(currentIndex: 1),
const SizedBox(height: 64.0),
@@ -74,6 +75,7 @@ class FinalCompletionOfDocumentsScreen extends StatelessWidget {
],
),
),
),
);
}
}
+3 -1
View File
@@ -39,7 +39,8 @@ class DesktopHomePage extends StatelessWidget {
if (homeViewModel.tenderApprovalsStateResponse != null &&
homeViewModel.data != null &&
homeViewModel.feedbackStats != null) {
return SingleChildScrollView(
return SafeArea(
child: SingleChildScrollView(
child: SizedBox(
width: 780,
child: Column(
@@ -61,6 +62,7 @@ class DesktopHomePage extends StatelessWidget {
],
),
),
),
);
}
return const Center(
+3 -1
View File
@@ -33,7 +33,8 @@ class MobileHomePage extends StatelessWidget {
if (homeViewModel.tenderApprovalsStateResponse != null &&
homeViewModel.data != null &&
homeViewModel.feedbackStats != null) {
return SingleChildScrollView(
return SafeArea(
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -53,6 +54,7 @@ class MobileHomePage extends StatelessWidget {
_bottomListView(homeViewModel),
],
),
),
);
}
return const Center(
+2
View File
@@ -50,6 +50,7 @@ class TabletHomePage extends StatelessWidget {
24.0.w(),
24.0.h(),
),
child: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -70,6 +71,7 @@ class TabletHomePage extends StatelessWidget {
],
),
),
),
);
}
return const Center(
@@ -59,7 +59,8 @@ class _LikedTendersDesktopPageState extends State<LikedTendersDesktopPage> {
key: scaffoldKey,
backgroundColor: AppColors.backgroundColor,
endDrawer: const LikeFiltersDrawer(),
body: Column(
body: SafeArea(
child: Column(
children: [
const DesktopNavigationWidget(currentIndex: 1, haveFilter: true),
const SizedBox(height: 40),
@@ -126,6 +127,7 @@ class _LikedTendersDesktopPageState extends State<LikedTendersDesktopPage> {
],
),
),
),
);
}
@@ -156,7 +156,8 @@ class _LikedTendersMobilePageState extends State<LikedTendersMobilePage> {
),
),
body: Column(
body: SafeArea(
child: Column(
children: [
Expanded(
child: Consumer<LikedTendersViewModel>(
@@ -243,6 +244,7 @@ class _LikedTendersMobilePageState extends State<LikedTendersMobilePage> {
],
),
),
),
);
}
}
@@ -63,7 +63,8 @@ class _LikedTendersTabletPageState extends State<LikedTendersTabletPage> {
backgroundColor: AppColors.backgroundColor,
appBar: tabletAppBar(title: LikedTendersStrings.likedTenders, key: key),
drawer: const TabletNavigationWidget(currentIndex: 1),
body: Center(
body: SafeArea(
child: Center(
child: SizedBox(
width: 720,
child: Column(
@@ -140,6 +141,7 @@ class _LikedTendersTabletPageState extends State<LikedTendersTabletPage> {
),
),
),
),
);
}
@@ -40,7 +40,8 @@ class _DesktopNotificationPageState extends State<DesktopNotificationPage>
Widget build(BuildContext context) {
final viewModel = context.watch<NotificationViewModel>();
return Scaffold(
return SafeArea(
child: Scaffold(
backgroundColor: AppColors.backgroundColor,
body: Column(
children: [
@@ -197,6 +198,7 @@ class _DesktopNotificationPageState extends State<DesktopNotificationPage>
),
],
),
),
);
}
}
@@ -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),
@@ -11,5 +11,14 @@ class NotificationStrings {
static const String currentPage = 'currentPage';
static const String of = 'of';
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/data/services/model/notification_data/notification_data.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 {
final NotificationItem notification;
@@ -20,17 +21,17 @@ class NotificationCard extends StatelessWidget {
padding: const EdgeInsets.all(16.0),
decoration: BoxDecoration(
color:
notification.type == 'reject'
notification.type == NotificationStrings.reject
? AppColors.orange10
: notification.type == 'info'
: notification.type == NotificationStrings.info
? AppColors.primary10Light
: AppColors.green0,
borderRadius: BorderRadius.circular(4),
border: Border.all(
color:
notification.type! == 'reject'
notification.type! == NotificationStrings.reject
? AppColors.warningColor
: notification.type == 'info' ? AppColors.primary20 : AppColors.green20,
: notification.type == NotificationStrings.info ? AppColors.primary20 : AppColors.green20,
),
),
child: Row(
@@ -39,9 +40,9 @@ class NotificationCard extends StatelessWidget {
Padding(
padding: EdgeInsets.only(top: 3.0.h()),
child: SvgPicture.asset(
notification.type! == 'info'
notification.type! == NotificationStrings.info
? AssetsManager.notification
: notification.type! == 'reject'
: notification.type! == NotificationStrings.reject
? AssetsManager.danger
: AssetsManager.tickCircle,
),
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:tm_app/core/utils/size_config.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';
@@ -21,7 +22,7 @@ class NotificationUnreadTab extends StatelessWidget {
viewModel.unreadNotificationResponse?.data?.notifications ?? [];
if (notifications.isEmpty) {
return const Center(child: Text('No unread notifications'));
return const Center(child: Text(NotificationStrings.noUnreadNotifications,));
}
return ListView.builder(
+3 -1
View File
@@ -64,7 +64,8 @@ class _DesktopProfilePageState extends State<DesktopProfilePage> {
return const Center(child: Text(CommonStrings.noData));
}
return Column(
return SafeArea(
child: Column(
children: [
const DesktopNavigationWidget(
currentIndex: 4, // Tenders index
@@ -143,6 +144,7 @@ class _DesktopProfilePageState extends State<DesktopProfilePage> {
),
),
],
),
);
},
),
+3 -1
View File
@@ -66,7 +66,8 @@ class _MobileProfilePageState extends State<MobileProfilePage> {
return const Center(child: Text(CommonStrings.noData));
}
return Padding(
return SafeArea(
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: 24.0.w(),
vertical: 16.0.h(),
@@ -137,6 +138,7 @@ class _MobileProfilePageState extends State<MobileProfilePage> {
),
],
),
),
);
},
),
+3 -3
View File
@@ -64,14 +64,14 @@ class _TabletProfilePageState extends State<TabletProfilePage> {
return const Center(child: Text(CommonStrings.noData));
}
return SafeArea(
child: Scaffold(
return Scaffold(
key: key,
backgroundColor: AppColors.backgroundColor,
appBar: tabletAppBar(title: ProfileStrings.profileTitle, key: key),
drawer: const TabletNavigationWidget(currentIndex: 4),
body: Padding(
body: SafeArea(
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: 24.0.w(),
vertical: 16.0.h(),
+3 -1
View File
@@ -41,12 +41,14 @@ class _DesktopSplashPageState extends State<DesktopSplashPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
body: SafeArea(
child: Center(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 100),
child: Image.asset(AssetsManager.logoBigPng),
),
),
),
);
}
}
+3 -1
View File
@@ -51,12 +51,14 @@ class _MobileSplashPageState extends State<MobileSplashPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
body: SafeArea(
child: Center(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 24.0.w()),
child: Image.asset(AssetsManager.logoBigPng, fit: BoxFit.cover),
),
),
),
);
}
}
+3 -1
View File
@@ -41,12 +41,14 @@ class _TabletSplashPageState extends State<TabletSplashPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
body: SafeArea(
child: Center(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 40),
child: Image.asset(AssetsManager.logoBigPng),
),
),
),
);
}
}
+3 -1
View File
@@ -51,7 +51,8 @@ class _DesktopTendersPageState extends State<DesktopTendersPage> {
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColors.backgroundColor,
body: Column(
body: SafeArea(
child: Column(
children: [
const DesktopNavigationWidget(currentIndex: 1),
SizedBox(height: 48.0.h()),
@@ -104,6 +105,7 @@ class _DesktopTendersPageState extends State<DesktopTendersPage> {
),
],
),
),
);
}
}
+3 -1
View File
@@ -60,11 +60,13 @@ class _MobileTendersPageState extends State<MobileTendersPage> {
return const Center(child: Text(CommonStrings.noData));
}
return Padding(
return SafeArea(
child: Padding(
padding: EdgeInsets.symmetric(vertical: 18.0.h()),
child: MainTendersSlider(
tenders: viewModel.tendersResponse?.data?.tenders ?? [],
),
),
);
},
),
@@ -51,6 +51,7 @@ class _TabletTendersPageState extends State<TabletTendersPage> {
}
return Expanded(
child: SingleChildScrollView(
child: SafeArea(
child: Padding(
padding: EdgeInsetsDirectional.only(
end: 24.0.w(),
@@ -61,6 +62,7 @@ class _TabletTendersPageState extends State<TabletTendersPage> {
),
),
),
),
);
},
),
@@ -39,7 +39,8 @@ class _YourTendersDesktopPageState extends State<YourTendersDesktopPage>
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColors.backgroundColor,
body: Column(
body: SafeArea(
child: Column(
children: [
const DesktopNavigationWidget(currentIndex: 1), // Tenders index
Expanded(
@@ -122,6 +123,7 @@ class _YourTendersDesktopPageState extends State<YourTendersDesktopPage>
),
],
),
),
);
}
@@ -38,7 +38,8 @@ class _YourTendersMobilePageState extends State<YourTendersMobilePage> {
return Scaffold(
backgroundColor: AppColors.backgroundColor,
appBar: appBar(context: context, title: YourTendersStrings.yourTenders),
body: Column(
body: SafeArea(
child: Column(
children: [
const FilterButton(platformType: PlatformType.mobile),
Expanded(
@@ -104,6 +105,7 @@ class _YourTendersMobilePageState extends State<YourTendersMobilePage> {
),
],
),
),
);
}
}
@@ -44,7 +44,8 @@ class _YourTendersTabletPageState extends State<YourTendersTabletPage>
backgroundColor: AppColors.backgroundColor,
appBar: tabletAppBar(title: YourTendersStrings.yourTenders, key: key),
drawer: const TabletNavigationWidget(currentIndex: 1),
body: Center(
body: SafeArea(
child: Center(
child: SizedBox(
width: 720,
child: Column(
@@ -125,6 +126,7 @@ class _YourTendersTabletPageState extends State<YourTendersTabletPage>
),
),
),
),
);
}