notifications api added.

main_design2.0
Sikander Saleem 2 years ago
parent 258fb2c333
commit 2c9f2dce08

@ -58,7 +58,7 @@ class URLs {
static get getSingleServiceRequest => "$_baseUrl/return/call/information"; // get static get getSingleServiceRequest => "$_baseUrl/return/call/information"; // get
static get getSuppliersAutoComplete => "$_baseUrl/Supplier/GetSuppliersAutoComplete"; static get getSuppliersAutoComplete => "$_baseUrl/Supplier/GetSuppliersAutoComplete";
static get getNotifications => "$_baseUrl/return/user/notification"; // get static get getSystemNotifications => "$_baseUrl/SystemNotification/GetSystemNotifications"; // get
static get getRecentNotifications => "$_baseUrl/return/user/recent/notification"; // get static get getRecentNotifications => "$_baseUrl/return/user/recent/notification"; // get
static get createRequest => "$_baseUrl/CallRequest/AddCallRequest"; // get static get createRequest => "$_baseUrl/CallRequest/AddCallRequest"; // get
static get createReport => "$_baseUrl/handle/create/report/issue"; // get static get createReport => "$_baseUrl/handle/create/report/issue"; // get

@ -3,7 +3,7 @@ import 'dart:convert';
import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:test_sa/models/app_notification.dart'; import 'package:test_sa/models/system_notification_model.dart';
import 'notification_manger.dart'; import 'notification_manger.dart';
@ -53,18 +53,20 @@ class FirebaseNotificationManger {
// Stream listener // Stream listener
FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler); FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler);
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) { // todo @sikander, check notifications payload, because notification model is different to need to check from backend
AppNotification notification = AppNotification.fromJson(message.data);
if (notification.path == null || notification.path.isEmpty) return;
Navigator.pushNamed(context, notification.path, arguments: notification.requestId);
});
FirebaseMessaging.onMessage.listen((RemoteMessage message) { // FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
AppNotification notification = AppNotification.fromJson(message.data); // SystemNotificationModel notification = SystemNotificationModel.fromJson(message.data);
NotificationManger.showNotification( // if (notification.path == null || notification.path.isEmpty) return;
title: message.notification.title, subtext: message.notification.body, hashcode: int.tryParse(notification.requestId ?? "") ?? 1, payload: json.encode(message.data)); // Navigator.pushNamed(context, notification.path, arguments: notification.requestId);
return; // });
}); //
// FirebaseMessaging.onMessage.listen((RemoteMessage message) {
// SystemNotificationModel notification = SystemNotificationModel.fromJson(message.data);
// NotificationManger.showNotification(
// title: message.notification.title, subtext: message.notification.body, hashcode: int.tryParse(notification.requestId ?? "") ?? 1, payload: json.encode(message.data));
// return;
// });
} }
} }

@ -2,8 +2,9 @@ import 'dart:convert';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:http/http.dart'; import 'package:http/http.dart';
import 'package:test_sa/controllers/api_routes/api_manager.dart';
import 'package:test_sa/controllers/api_routes/urls.dart'; import 'package:test_sa/controllers/api_routes/urls.dart';
import 'package:test_sa/models/app_notification.dart'; import 'package:test_sa/models/system_notification_model.dart';
import 'package:test_sa/models/user.dart'; import 'package:test_sa/models/user.dart';
class NotificationsProvider extends ChangeNotifier { class NotificationsProvider extends ChangeNotifier {
@ -12,7 +13,7 @@ class NotificationsProvider extends ChangeNotifier {
//reset provider data //reset provider data
void reset() { void reset() {
notifications = null; notifications = [];
nextPage = true; nextPage = true;
stateCode = null; stateCode = null;
} }
@ -26,7 +27,7 @@ class NotificationsProvider extends ChangeNotifier {
bool nextPage = true; bool nextPage = true;
// list of user requests // list of user requests
List<AppNotification> notifications; List<SystemNotificationModel> notifications = [];
// when requests in-process _loading = true // when requests in-process _loading = true
// done _loading = true // done _loading = true
@ -38,7 +39,7 @@ class NotificationsProvider extends ChangeNotifier {
/// return state code if request complete may be 200, 404 or 403 /// return state code if request complete may be 200, 404 or 403
/// for more details check http state manager /// for more details check http state manager
/// lib\controllers\http_status_manger\http_status_manger.dart /// lib\controllers\http_status_manger\http_status_manger.dart
Future<int> getNotifications({ Future<int> getSystemNotifications({
@required String host, @required String host,
@required User user, @required User user,
@required int hospitalId, @required int hospitalId,
@ -47,19 +48,17 @@ class NotificationsProvider extends ChangeNotifier {
isLoading = true; isLoading = true;
notifyListeners(); notifyListeners();
Response response; Response response;
// userId = 397.toString(); // testing id to view data
try { try {
response = await get( final Map<String, dynamic> body = {"pageSize": pageItemNumber, "pageNumber": notifications.length ~/ pageItemNumber + 1};
Uri.parse(URLs.getNotifications + response = await ApiManager.instance.post(URLs.getSystemNotifications, body: body);
"?uid=${user.id}"
"&token=${user.token}"
"&page=${(notifications?.length ?? 0) ~/ pageItemNumber}"),
headers: {"Content-Type": "application/json; charset=utf-8"});
stateCode = response.statusCode; stateCode = response.statusCode;
if (response.statusCode >= 200 && response.statusCode < 300) { if (response.statusCode >= 200 && response.statusCode < 300) {
// client's request was successfully received // client's request was successfully received
List requestsListJson = json.decode(utf8.decode(response.bodyBytes)); // List requestsListJson = json.decode(utf8.decode(response.bodyBytes));
List<AppNotification> _serviceRequestsPage = requestsListJson.map((request) => AppNotification.fromJson(request)).toList();
List requestsListJson = json.decode(response.body)["data"];
List<SystemNotificationModel> _serviceRequestsPage = requestsListJson.map((request) => SystemNotificationModel.fromJson(request)).toList();
if (notifications == null) notifications = []; if (notifications == null) notifications = [];
notifications.addAll(_serviceRequestsPage); notifications.addAll(_serviceRequestsPage);
if (_serviceRequestsPage.length == pageItemNumber) { if (_serviceRequestsPage.length == pageItemNumber) {
@ -72,6 +71,7 @@ class NotificationsProvider extends ChangeNotifier {
notifyListeners(); notifyListeners();
return response.statusCode; return response.statusCode;
} catch (error) { } catch (error) {
print(error);
isLoading = false; isLoading = false;
stateCode = -1; stateCode = -1;
notifyListeners(); notifyListeners();
@ -84,7 +84,7 @@ class NotificationsProvider extends ChangeNotifier {
/// return state code if request complete may be 200, 404 or 403 /// return state code if request complete may be 200, 404 or 403
/// for more details check http state manager /// for more details check http state manager
/// lib\controllers\http_status_manger\http_status_manger.dart /// lib\controllers\http_status_manger\http_status_manger.dart
Future<List<AppNotification>> getRecentNotifications({ Future<List<SystemNotificationModel>> getRecentNotifications({
@required String host, @required String host,
@required User user, @required User user,
}) async { }) async {
@ -92,13 +92,13 @@ class NotificationsProvider extends ChangeNotifier {
//userId = 397.toString(); // testing id to view data //userId = 397.toString(); // testing id to view data
try { try {
response = await get(Uri.parse(host + URLs.getNotifications + "?uid=${user.id}&token=${user.token}"), headers: {"Content-Type": "application/json; charset=utf-8"}); response = await get(Uri.parse(host + URLs.getSystemNotifications + "?uid=${user.id}&token=${user.token}"), headers: {"Content-Type": "application/json; charset=utf-8"});
stateCode = response.statusCode; stateCode = response.statusCode;
if (response.statusCode >= 200 && response.statusCode < 300) { if (response.statusCode >= 200 && response.statusCode < 300) {
// client's request was successfully received // client's request was successfully received
List requestsListJson = json.decode(utf8.decode(response.bodyBytes)); List requestsListJson = json.decode(utf8.decode(response.bodyBytes));
List<AppNotification> _recentNotifications = requestsListJson.map((request) => AppNotification.fromJson(request)).toList(); List<SystemNotificationModel> _recentNotifications = requestsListJson.map((request) => SystemNotificationModel.fromJson(request)).toList();
return _recentNotifications; return _recentNotifications;
} }
return null; return null;

@ -1,26 +0,0 @@
import 'package:test_sa/views/pages/user/requests/future_request_service_details.dart';
class AppNotification {
String requestId;
String title;
String description;
String date;
String path;
AppNotification({
this.requestId,
this.title,
this.description,
this.date,
this.path,
});
factory AppNotification.fromJson(Map<String, dynamic> parsedJson) {
return AppNotification(
requestId: parsedJson["nid"],
title: parsedJson["call_client"] ?? parsedJson["title"],
description: parsedJson["task_description"],
date: parsedJson["creation_date"],
path: FutureRequestServiceDetails.id);
}
}

@ -0,0 +1,51 @@
import 'package:test_sa/views/pages/user/requests/future_request_service_details.dart';
class SystemNotificationModel {
String userId;
String userName;
String title;
String text;
int referenceId;
int sourceId;
String sourceName;
bool readed;
String readingDate;
int id;
String createdOn;
String modifiedOn;
SystemNotificationModel(
{this.userId, this.userName, this.title, this.text, this.referenceId, this.sourceId, this.sourceName, this.readed, this.readingDate, this.id, this.createdOn, this.modifiedOn});
SystemNotificationModel.fromJson(Map<String, dynamic> json) {
userId = json['userId'];
userName = json['userName'];
title = json['title'];
text = json['text'];
referenceId = json['referenceId'];
sourceId = json['sourceId'];
sourceName = json['sourceName'];
readed = json['readed'];
readingDate = json['readingDate'];
id = json['id'];
createdOn = json['createdOn'];
modifiedOn = json['modifiedOn'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['userId'] = this.userId;
data['userName'] = this.userName;
data['title'] = this.title;
data['text'] = this.text;
data['referenceId'] = this.referenceId;
data['sourceId'] = this.sourceId;
data['sourceName'] = this.sourceName;
data['readed'] = this.readed;
data['readingDate'] = this.readingDate;
data['id'] = this.id;
data['createdOn'] = this.createdOn;
data['modifiedOn'] = this.modifiedOn;
return data;
}
}

@ -6,6 +6,9 @@ import 'package:test_sa/extensions/int_extensions.dart';
import 'package:test_sa/extensions/text_extensions.dart'; import 'package:test_sa/extensions/text_extensions.dart';
import 'package:test_sa/extensions/widget_extensions.dart'; import 'package:test_sa/extensions/widget_extensions.dart';
import 'package:test_sa/new_views/app_style/app_color.dart'; import 'package:test_sa/new_views/app_style/app_color.dart';
import 'package:test_sa/views/app_style/colors.dart';
import 'package:test_sa/views/app_style/sizing.dart';
import 'package:test_sa/views/pages/user/notifications/notifications_page.dart';
import '../../controllers/providers/api/user_provider.dart'; import '../../controllers/providers/api/user_provider.dart';
import '../../controllers/providers/settings/setting_provider.dart'; import '../../controllers/providers/settings/setting_provider.dart';
@ -60,7 +63,7 @@ class AppDrawer extends StatelessWidget {
ListView( ListView(
padding: EdgeInsets.only(top: 24), padding: EdgeInsets.only(top: 24),
children: [ children: [
drawerItem("drawer_notification", "Notification"), drawerItem("drawer_notification", "Notification").onPress(() => Navigator.of(context).pushNamed(NotificationsPage.id)),
18.height, 18.height,
drawerItem("help_center", "Help Center"), drawerItem("help_center", "Help Center"),
18.height, 18.height,
@ -97,7 +100,7 @@ class AppDrawer extends StatelessWidget {
), ),
], ],
), ),
drawerItem("logout", "Logout").onPress(() { drawerItem("logout", "Logout", color: AppColor.red50).onPress(() {
/// TODO [zaid] : show dialog before logout /// TODO [zaid] : show dialog before logout
// bool result = await showDialog( // bool result = await showDialog(
// context: context, // context: context,
@ -115,9 +118,21 @@ class AppDrawer extends StatelessWidget {
}), }),
18.height, 18.height,
1.divider, 1.divider,
24.height, 18.height,
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Powered By Cloud Solutions",
style: Theme.of(context).textTheme.headline6.copyWith(fontWeight: FontWeight.w500, color: AColors.grey3A, fontSize: 12),
textScaleFactor: AppStyle.getScaleFactor(context),
),
6.width,
Image.asset("assets/images/cloud_logo.png", width: 32, height: 32)
],
)
], ],
).paddingOnly(top: 66, start: 16, end: 24, bottom: 62), ).paddingOnly(top: 66, start: 16, end: 24, bottom: 18),
); );
} }
@ -133,7 +148,7 @@ class AppDrawer extends StatelessWidget {
16.width, 16.width,
Text( Text(
title, title,
style: AppTextStyles.heading6.copyWith(color: const Color(0xFF3B3D4A)), style: AppTextStyles.heading6.copyWith(color: color ?? const Color(0xFF3B3D4A)),
), ),
], ],
); );

@ -8,7 +8,7 @@ import 'package:test_sa/controllers/notification/notification_manger.dart';
import 'package:test_sa/controllers/providers/api/user_provider.dart'; import 'package:test_sa/controllers/providers/api/user_provider.dart';
import 'package:test_sa/controllers/providers/settings/setting_provider.dart'; import 'package:test_sa/controllers/providers/settings/setting_provider.dart';
import 'package:test_sa/extensions/widget_extensions.dart'; import 'package:test_sa/extensions/widget_extensions.dart';
import 'package:test_sa/models/app_notification.dart'; import 'package:test_sa/models/system_notification_model.dart';
import 'package:test_sa/new_views/pages/land_page/land_page.dart'; import 'package:test_sa/new_views/pages/land_page/land_page.dart';
import 'package:test_sa/new_views/pages/login_page.dart'; import 'package:test_sa/new_views/pages/login_page.dart';
@ -31,9 +31,10 @@ class _SplashPageState extends State<SplashPage> {
void initState() { void initState() {
Firebase.initializeApp(); Firebase.initializeApp();
NotificationManger.initialisation((notificationDetails) { NotificationManger.initialisation((notificationDetails) {
AppNotification notification = AppNotification.fromJson(json.decode(notificationDetails.payload)); // todo @sikander, check notifications payload, because notification model is different to need to check from backend
if (notification.path == null || notification.path.isEmpty) return; // SystemNotificationModel notification = SystemNotificationModel.fromJson(json.decode(notificationDetails.payload));
Navigator.pushNamed(context, notification.path, arguments: notification.requestId); // if (notification.path == null || notification.path.isEmpty) return;
// Navigator.pushNamed(context, notification.path, arguments: notification.requestId);
}, (id, title, body, payload) async {}); }, (id, title, body, payload) async {});
super.initState(); super.initState();
} }

@ -7,7 +7,7 @@ import 'package:provider/provider.dart';
import 'package:test_sa/controllers/notification/notification_manger.dart'; import 'package:test_sa/controllers/notification/notification_manger.dart';
import 'package:test_sa/controllers/providers/api/user_provider.dart'; import 'package:test_sa/controllers/providers/api/user_provider.dart';
import 'package:test_sa/controllers/providers/settings/setting_provider.dart'; import 'package:test_sa/controllers/providers/settings/setting_provider.dart';
import 'package:test_sa/models/app_notification.dart'; import 'package:test_sa/models/system_notification_model.dart';
import 'package:test_sa/models/user.dart'; import 'package:test_sa/models/user.dart';
import 'package:test_sa/new_views/pages/land_page/land_page.dart'; import 'package:test_sa/new_views/pages/land_page/land_page.dart';
@ -39,9 +39,10 @@ class _SplashScreenState extends State<SplashScreen> {
Firebase.initializeApp(); Firebase.initializeApp();
NotificationManger.initialisation((notificationDetails) { NotificationManger.initialisation((notificationDetails) {
AppNotification notification = AppNotification.fromJson(json.decode(notificationDetails.payload)); // todo @sikander, check notifications payload, because notification model is different to need to check from backend
if (notification.path == null || notification.path.isEmpty) return; // SystemNotificationModel notification = SystemNotificationModel.fromJson(json.decode(notificationDetails.payload));
Navigator.pushNamed(context, notification.path, arguments: notification.requestId); // if (notification.path == null || notification.path.isEmpty) return;
// Navigator.pushNamed(context, notification.path, arguments: notification.requestId);
}, (id, title, body, payload) async {}); }, (id, title, body, payload) async {});
super.initState(); super.initState();
} }

@ -1,7 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:test_sa/controllers/localization/localization.dart'; import 'package:test_sa/controllers/localization/localization.dart';
import 'package:test_sa/extensions/context_extension.dart'; import 'package:test_sa/extensions/context_extension.dart';
import 'package:test_sa/models/app_notification.dart'; import 'package:test_sa/models/system_notification_model.dart';
import 'package:test_sa/models/subtitle.dart'; import 'package:test_sa/models/subtitle.dart';
import 'package:test_sa/views/pages/user/requests/future_request_service_details.dart'; import 'package:test_sa/views/pages/user/requests/future_request_service_details.dart';
import 'package:test_sa/views/widgets/loaders/lazy_loading.dart'; import 'package:test_sa/views/widgets/loaders/lazy_loading.dart';
@ -9,7 +9,7 @@ import 'package:test_sa/views/widgets/loaders/no_item_found.dart';
import 'package:test_sa/views/widgets/notifications/notification_item.dart'; import 'package:test_sa/views/widgets/notifications/notification_item.dart';
class NotificationsList extends StatelessWidget { class NotificationsList extends StatelessWidget {
final List<AppNotification> notifications; final List<SystemNotificationModel> notifications;
final bool nextPage; final bool nextPage;
final Future<void> Function() onLazyLoad; final Future<void> Function() onLazyLoad;
@ -34,7 +34,8 @@ class NotificationsList extends StatelessWidget {
return NotificationItem( return NotificationItem(
notification: notifications[itemIndex], notification: notifications[itemIndex],
onPressed: (notification) { onPressed: (notification) {
Navigator.of(context).pushNamed(FutureRequestServiceDetails.id, arguments: notification.requestId); // todo @sikander, check notifications payload, because notification model is different to need to check from backend
//Navigator.of(context).pushNamed(FutureRequestServiceDetails.id, arguments: notification.requestId);
}, },
); );
}), }),

@ -6,6 +6,7 @@ import 'package:test_sa/controllers/providers/api/user_provider.dart';
import 'package:test_sa/controllers/providers/settings/setting_provider.dart'; import 'package:test_sa/controllers/providers/settings/setting_provider.dart';
import 'package:test_sa/extensions/context_extension.dart'; import 'package:test_sa/extensions/context_extension.dart';
import 'package:test_sa/models/subtitle.dart'; import 'package:test_sa/models/subtitle.dart';
import 'package:test_sa/new_views/common_widgets/default_app_bar.dart';
import 'package:test_sa/views/app_style/colors.dart'; import 'package:test_sa/views/app_style/colors.dart';
import 'package:test_sa/views/pages/user/notifications/notifications_list.dart'; import 'package:test_sa/views/pages/user/notifications/notifications_list.dart';
import 'package:test_sa/views/widgets/buttons/app_back_button.dart'; import 'package:test_sa/views/widgets/buttons/app_back_button.dart';
@ -28,8 +29,8 @@ class _NotificationsPageState extends State<NotificationsPage> with TickerProvid
_notificationsProvider = Provider.of<NotificationsProvider>(context); _notificationsProvider = Provider.of<NotificationsProvider>(context);
_userProvider = Provider.of<UserProvider>(context); _userProvider = Provider.of<UserProvider>(context);
_settingProvider = Provider.of<SettingProvider>(context); _settingProvider = Provider.of<SettingProvider>(context);
return Scaffold( return Scaffold(
appBar: DefaultAppBar(title: context.translation.notifications),
body: SafeArea( body: SafeArea(
child: LoadingManager( child: LoadingManager(
isLoading: _notificationsProvider.isLoading, isLoading: _notificationsProvider.isLoading,
@ -37,56 +38,22 @@ class _NotificationsPageState extends State<NotificationsPage> with TickerProvid
stateCode: _notificationsProvider.stateCode, stateCode: _notificationsProvider.stateCode,
onRefresh: () async { onRefresh: () async {
_notificationsProvider.reset(); _notificationsProvider.reset();
await _notificationsProvider.getNotifications( await _notificationsProvider.getSystemNotifications(
user: _userProvider.user, user: _userProvider.user,
host: _settingProvider.host, host: _settingProvider.host,
hospitalId: _userProvider.user.clientId, hospitalId: _userProvider.user.clientId,
); );
}, },
child: Stack( child: NotificationsList(
children: [ nextPage: _notificationsProvider.nextPage,
Column( onLazyLoad: () async {
children: [ await _notificationsProvider.getSystemNotifications(
Container( user: _userProvider.user,
color: AColors.primaryColor, host: _settingProvider.host,
padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 4), hospitalId: _userProvider.user.clientId,
child: Column( );
children: [ },
Row( notifications: _notificationsProvider.notifications,
children: [
ABackButton(),
Expanded(
child: Center(
child: Text(
context.translation.notifications,
style: Theme.of(context).textTheme.headline6.copyWith(color: AColors.white, fontStyle: FontStyle.italic),
),
),
),
SizedBox(
width: 48,
)
],
),
],
),
),
Expanded(
child: NotificationsList(
nextPage: _notificationsProvider.nextPage,
onLazyLoad: () async {
await _notificationsProvider.getNotifications(
user: _userProvider.user,
host: _settingProvider.host,
hospitalId: _userProvider.user.clientId,
);
},
notifications: _notificationsProvider.notifications,
),
),
],
),
],
), ),
), ),
), ),

@ -1,11 +1,11 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:test_sa/models/app_notification.dart'; import 'package:test_sa/models/system_notification_model.dart';
import 'package:test_sa/views/app_style/colors.dart'; import 'package:test_sa/views/app_style/colors.dart';
import 'package:test_sa/views/app_style/sizing.dart'; import 'package:test_sa/views/app_style/sizing.dart';
class NotificationItem extends StatelessWidget { class NotificationItem extends StatelessWidget {
final AppNotification notification; final SystemNotificationModel notification;
final Function(AppNotification) onPressed; final Function(SystemNotificationModel) onPressed;
const NotificationItem({Key key, this.notification, this.onPressed}) : super(key: key); const NotificationItem({Key key, this.notification, this.onPressed}) : super(key: key);
@ -36,7 +36,7 @@ class NotificationItem extends StatelessWidget {
), ),
), ),
Text( Text(
notification.date ?? "complaint not available", notification.createdOn ?? "complaint not available",
style: Theme.of(context).textTheme.subtitle1.copyWith(color: AColors.white, fontSize: 12, fontWeight: FontWeight.bold), style: Theme.of(context).textTheme.subtitle1.copyWith(color: AColors.white, fontSize: 12, fontWeight: FontWeight.bold),
), ),
], ],
@ -45,7 +45,7 @@ class NotificationItem extends StatelessWidget {
color: AColors.white, color: AColors.white,
), ),
Text( Text(
notification.description ?? "complaint not available", notification.text ?? "complaint not available",
style: Theme.of(context).textTheme.subtitle1.copyWith( style: Theme.of(context).textTheme.subtitle1.copyWith(
color: AColors.white, color: AColors.white,
fontSize: 14, fontSize: 14,

Loading…
Cancel
Save