finish step from notifications_page and create notification_details_page
parent
9f2beceb22
commit
5bd3c7d9ce
Binary file not shown.
|
After Width: | Height: | Size: 2.7 KiB |
@ -0,0 +1,15 @@
|
|||||||
|
class MarkMessageAsReadRequestModel {
|
||||||
|
int notificationPoolID;
|
||||||
|
|
||||||
|
MarkMessageAsReadRequestModel({this.notificationPoolID});
|
||||||
|
|
||||||
|
MarkMessageAsReadRequestModel.fromJson(Map<String, dynamic> json) {
|
||||||
|
notificationPoolID = json['NotificationPoolID'];
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||||
|
data['NotificationPoolID'] = this.notificationPoolID;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,25 +1,39 @@
|
|||||||
import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
|
import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
|
||||||
import 'package:diplomaticquarterapp/core/model/notifications/get_notifications_request_model.dart';
|
import 'package:diplomaticquarterapp/core/model/notifications/get_notifications_request_model.dart';
|
||||||
import 'package:diplomaticquarterapp/core/model/notifications/get_notifications_response_model.dart';
|
import 'package:diplomaticquarterapp/core/model/notifications/get_notifications_response_model.dart';
|
||||||
|
import 'package:diplomaticquarterapp/core/model/notifications/mark_message_as_read_request_model.dart';
|
||||||
import 'package:diplomaticquarterapp/core/service/notifications_service.dart';
|
import 'package:diplomaticquarterapp/core/service/notifications_service.dart';
|
||||||
|
|
||||||
import '../../locator.dart';
|
import '../../locator.dart';
|
||||||
import 'base_view_model.dart';
|
import 'base_view_model.dart';
|
||||||
|
|
||||||
class NotificationViewModel extends BaseViewModel {
|
class NotificationViewModel extends BaseViewModel {
|
||||||
NotificationService _notificationService =
|
NotificationService _notificationService = locator<NotificationService>();
|
||||||
locator<NotificationService>();
|
|
||||||
|
|
||||||
List<GetNotificationsResponseModel> get notifications => _notificationService.notificationsList;
|
List<GetNotificationsResponseModel> get notifications =>
|
||||||
|
_notificationService.notificationsList;
|
||||||
|
|
||||||
Future getNotifications() async {
|
Future getNotifications(
|
||||||
|
GetNotificationsRequestModel getNotificationsRequestModel) async {
|
||||||
setState(ViewState.Busy);
|
setState(ViewState.Busy);
|
||||||
GetNotificationsRequestModel getNotificationsRequestModel = new GetNotificationsRequestModel(currentPage: 0,pagingSize: 14,notificationStatusID: 2);
|
await _notificationService
|
||||||
await _notificationService.getAllNotifications(getNotificationsRequestModel);
|
.getAllNotifications(getNotificationsRequestModel);
|
||||||
if (_notificationService.hasError) {
|
if (_notificationService.hasError) {
|
||||||
error = _notificationService.error;
|
error = _notificationService.error;
|
||||||
setState(ViewState.Error);
|
setState(ViewState.Error);
|
||||||
} else
|
} else
|
||||||
setState(ViewState.Idle);
|
setState(ViewState.Idle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future markAsRead(id) async {
|
||||||
|
// setState(ViewState.Busy);
|
||||||
|
MarkMessageAsReadRequestModel markMessageAsReadRequestModel =
|
||||||
|
new MarkMessageAsReadRequestModel(notificationPoolID: id);
|
||||||
|
await _notificationService.markAsRead(markMessageAsReadRequestModel);
|
||||||
|
// if (_notificationService.hasError) {
|
||||||
|
// error = _notificationService.error;
|
||||||
|
// setState(ViewState.Error);
|
||||||
|
// } else
|
||||||
|
// setState(ViewState.Idle);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -0,0 +1,103 @@
|
|||||||
|
import 'package:diplomaticquarterapp/core/model/notifications/get_notifications_response_model.dart';
|
||||||
|
import 'package:diplomaticquarterapp/core/viewModels/notifications_view_model.dart';
|
||||||
|
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
|
||||||
|
import 'package:diplomaticquarterapp/uitl/date_uitl.dart';
|
||||||
|
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
|
||||||
|
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
|
||||||
|
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
|
||||||
|
import 'package:diplomaticquarterapp/widgets/progress_indicator/app_circular_progress_Indeicator.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class NotificationsDetailsPage extends StatelessWidget {
|
||||||
|
final GetNotificationsResponseModel notification;
|
||||||
|
|
||||||
|
NotificationsDetailsPage({this.notification});
|
||||||
|
|
||||||
|
getDateForm(String date) {
|
||||||
|
DateTime d = DateUtil.convertStringToDate(date);
|
||||||
|
String monthName = DateUtil.getMonth(d.month).toString();
|
||||||
|
TimeOfDay timeOfDay = TimeOfDay(hour: d.hour, minute: d.minute);
|
||||||
|
String minute = timeOfDay.minute < 10
|
||||||
|
? timeOfDay.minute.toString().padLeft(2, '0')
|
||||||
|
: timeOfDay.minute.toString();
|
||||||
|
|
||||||
|
String hour = '${timeOfDay.hourOfPeriod}:$minute';
|
||||||
|
if (timeOfDay.period == DayPeriod.am) {
|
||||||
|
hour = hour + "AM";
|
||||||
|
} else {
|
||||||
|
{
|
||||||
|
hour = hour + "PM";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return monthName + ',${d.day},${d.year}, $hour';
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return BaseView<NotificationViewModel>(
|
||||||
|
builder: (_, model, widget) => AppScaffold(
|
||||||
|
isShowAppBar: true,
|
||||||
|
appBarTitle: TranslationBase.of(context).notificationDetails,
|
||||||
|
body: SingleChildScrollView(
|
||||||
|
child: Center(
|
||||||
|
child: FractionallySizedBox(
|
||||||
|
widthFactor: 0.9,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
SizedBox(
|
||||||
|
height: 25,
|
||||||
|
),
|
||||||
|
Container(
|
||||||
|
// margin: EdgeInsets.only(left: 30),
|
||||||
|
width: double.infinity,
|
||||||
|
color: Colors.grey[400],
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Texts(
|
||||||
|
getDateForm(notification.createdOn),
|
||||||
|
fontSize: 16,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: 15,
|
||||||
|
),
|
||||||
|
if (notification.messageTypeData.length != 0)
|
||||||
|
FractionallySizedBox(
|
||||||
|
widthFactor: 0.9,
|
||||||
|
child: Image.network(notification.messageTypeData,
|
||||||
|
loadingBuilder: (BuildContext context, Widget child,
|
||||||
|
ImageChunkEvent loadingProgress) {
|
||||||
|
if (loadingProgress == null) return child;
|
||||||
|
return Center(
|
||||||
|
child: SizedBox(
|
||||||
|
width: 40.0,
|
||||||
|
height: 40.0,
|
||||||
|
child: AppCircularProgressIndicator(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
fit: BoxFit
|
||||||
|
.fill) //Image.network(notification.messageTypeData),
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: 15,
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Center(
|
||||||
|
child: Texts(notification.message),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,142 @@
|
|||||||
|
import 'package:diplomaticquarterapp/core/model/notifications/get_notifications_request_model.dart';
|
||||||
|
import 'package:diplomaticquarterapp/core/viewModels/notifications_view_model.dart';
|
||||||
|
import 'package:diplomaticquarterapp/pages/DrawerPages/notifications/notification_details_page.dart';
|
||||||
|
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
|
||||||
|
import 'package:diplomaticquarterapp/uitl/date_uitl.dart';
|
||||||
|
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
|
||||||
|
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
|
||||||
|
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||||
|
|
||||||
|
// ignore: must_be_immutable
|
||||||
|
class NotificationsPage extends StatelessWidget {
|
||||||
|
getDateForm(String date) {
|
||||||
|
DateTime d = DateUtil.convertStringToDate(date);
|
||||||
|
String monthName = DateUtil.getMonth(d.month).toString();
|
||||||
|
TimeOfDay timeOfDay = TimeOfDay(hour: d.hour, minute: d.minute);
|
||||||
|
String minute = timeOfDay.minute < 10
|
||||||
|
? timeOfDay.minute.toString().padLeft(2, '0')
|
||||||
|
: timeOfDay.minute.toString();
|
||||||
|
|
||||||
|
String hour = '${timeOfDay.hourOfPeriod}:$minute';
|
||||||
|
if (timeOfDay.period == DayPeriod.am) {
|
||||||
|
hour = hour + "AM";
|
||||||
|
} else {
|
||||||
|
{
|
||||||
|
hour = hour + "PM";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//DayPeriod.am
|
||||||
|
return monthName + ',${d.day},${d.year}, $hour';
|
||||||
|
}
|
||||||
|
|
||||||
|
int currentIndex = 0;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
var prescriptionReport;
|
||||||
|
return BaseView<NotificationViewModel>(
|
||||||
|
onModelReady: (model) {
|
||||||
|
GetNotificationsRequestModel getNotificationsRequestModel =
|
||||||
|
new GetNotificationsRequestModel(
|
||||||
|
currentPage: currentIndex,
|
||||||
|
pagingSize: 14,
|
||||||
|
notificationStatusID: 2);
|
||||||
|
|
||||||
|
model.getNotifications(getNotificationsRequestModel);
|
||||||
|
},
|
||||||
|
builder: (_, model, widget) => AppScaffold(
|
||||||
|
isShowAppBar: true,
|
||||||
|
appBarTitle: TranslationBase.of(context).notifications,
|
||||||
|
baseViewModel: model,
|
||||||
|
body: ListView(
|
||||||
|
children: model.notifications
|
||||||
|
.map(
|
||||||
|
(notification) => InkWell(
|
||||||
|
onTap: () async {
|
||||||
|
if(!notification.isRead)
|
||||||
|
await model.markAsRead(notification.id);
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (BuildContext context) =>
|
||||||
|
NotificationsDetailsPage(
|
||||||
|
notification: notification,
|
||||||
|
)));
|
||||||
|
},
|
||||||
|
child: Container(
|
||||||
|
width: double.infinity,
|
||||||
|
margin: EdgeInsets.only(
|
||||||
|
top: 5, left: 10, right: 10, bottom: 5),
|
||||||
|
padding: EdgeInsets.all(8.0),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
borderRadius: BorderRadius.all(
|
||||||
|
Radius.circular(10.0),
|
||||||
|
),
|
||||||
|
border: Border.all(
|
||||||
|
color: notification.isRead
|
||||||
|
? Colors.grey[200]
|
||||||
|
: Theme.of(context).primaryColor,
|
||||||
|
width: 0.5),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
children: <Widget>[
|
||||||
|
Expanded(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: <Widget>[
|
||||||
|
Texts(getDateForm(notification.createdOn)),
|
||||||
|
SizedBox(
|
||||||
|
height: 5,
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Texts(notification.message)),
|
||||||
|
if (notification.messageType == "image")
|
||||||
|
Icon(FontAwesomeIcons.images)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: 5,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
width: 15,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.toList()
|
||||||
|
..add(
|
||||||
|
InkWell(
|
||||||
|
onTap: () {
|
||||||
|
currentIndex++;
|
||||||
|
GetNotificationsRequestModel
|
||||||
|
getNotificationsRequestModel =
|
||||||
|
new GetNotificationsRequestModel(
|
||||||
|
currentPage: currentIndex,
|
||||||
|
pagingSize: 14,
|
||||||
|
notificationStatusID: 2);
|
||||||
|
|
||||||
|
model.getNotifications(getNotificationsRequestModel);
|
||||||
|
},
|
||||||
|
child: Center(
|
||||||
|
child: Image.asset('assets/images/notf.png'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,89 +0,0 @@
|
|||||||
import 'package:diplomaticquarterapp/core/viewModels/notifications_view_model.dart';
|
|
||||||
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
|
|
||||||
import 'package:diplomaticquarterapp/uitl/date_uitl.dart';
|
|
||||||
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
|
|
||||||
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
|
|
||||||
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
class NotificationsPage extends StatelessWidget {
|
|
||||||
getDateForm(String date) {
|
|
||||||
DateTime d = DateUtil.convertStringToDate(date);
|
|
||||||
String monthName = DateUtil.getMonth(d.month).toString();
|
|
||||||
TimeOfDay timeOfDay = TimeOfDay(hour: d.hour, minute: d.minute);
|
|
||||||
String minute = timeOfDay.minute < 10
|
|
||||||
? timeOfDay.minute.toString().padLeft(2, '0')
|
|
||||||
: timeOfDay.minute.toString();
|
|
||||||
|
|
||||||
String hour = '${timeOfDay.hourOfPeriod}:$minute';
|
|
||||||
if (timeOfDay.period == DayPeriod.am) {
|
|
||||||
hour = hour + "AM";
|
|
||||||
} else {
|
|
||||||
{
|
|
||||||
hour = hour + "PM";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//DayPeriod.am
|
|
||||||
return monthName + ',${d.day},${d.year}, $hour';
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
var prescriptionReport;
|
|
||||||
return BaseView<NotificationViewModel>(
|
|
||||||
onModelReady: (model) => model.getNotifications(),
|
|
||||||
builder: (_, model, widget) => AppScaffold(
|
|
||||||
isShowAppBar: true,
|
|
||||||
appBarTitle: TranslationBase.of(context).notifications,
|
|
||||||
baseViewModel: model,
|
|
||||||
body: ListView.builder(
|
|
||||||
itemBuilder: (context, index) => Container(
|
|
||||||
width: double.infinity,
|
|
||||||
margin: EdgeInsets.only(top: 5, left: 10, right: 10, bottom: 5),
|
|
||||||
padding: EdgeInsets.all(8.0),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.white,
|
|
||||||
borderRadius: BorderRadius.all(
|
|
||||||
Radius.circular(10.0),
|
|
||||||
),
|
|
||||||
border: Border.all(
|
|
||||||
color: model.notifications[index].isRead
|
|
||||||
? Colors.grey[200]
|
|
||||||
: Theme.of(context).primaryColor,
|
|
||||||
width: 0.5),
|
|
||||||
),
|
|
||||||
child: Row(
|
|
||||||
children: <Widget>[
|
|
||||||
Expanded(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(8.0),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: <Widget>[
|
|
||||||
Texts(
|
|
||||||
getDateForm(model.notifications[index].createdOn)),
|
|
||||||
SizedBox(
|
|
||||||
height: 5,
|
|
||||||
),
|
|
||||||
Texts(model.notifications[index].message),
|
|
||||||
SizedBox(
|
|
||||||
height: 5,
|
|
||||||
),
|
|
||||||
Texts(model.notifications[index].notificationType),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
SizedBox(
|
|
||||||
width: 15,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
itemCount: model.notifications.length,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue