update notification to read on click
This commit is contained in:
@@ -1,7 +1,10 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:patient_manager/main.dart';
|
import 'package:patient_manager/main.dart';
|
||||||
|
import 'package:patient_manager/mih_components/mih_pop_up_messages/mih_error_message.dart';
|
||||||
|
import 'package:patient_manager/mih_env/env.dart';
|
||||||
import 'package:patient_manager/mih_objects/app_user.dart';
|
import 'package:patient_manager/mih_objects/app_user.dart';
|
||||||
import 'package:patient_manager/mih_objects/notification.dart';
|
import 'package:patient_manager/mih_objects/notification.dart';
|
||||||
|
import 'package:supertokens_flutter/http.dart' as http;
|
||||||
|
|
||||||
class MIHNotificationDrawer extends StatefulWidget {
|
class MIHNotificationDrawer extends StatefulWidget {
|
||||||
final AppUser signedInUser;
|
final AppUser signedInUser;
|
||||||
@@ -20,6 +23,35 @@ class MIHNotificationDrawer extends StatefulWidget {
|
|||||||
|
|
||||||
class _MIHNotificationDrawerState extends State<MIHNotificationDrawer> {
|
class _MIHNotificationDrawerState extends State<MIHNotificationDrawer> {
|
||||||
late List<List<String>> notificationList;
|
late List<List<String>> notificationList;
|
||||||
|
final baseAPI = AppEnviroment.baseApiUrl;
|
||||||
|
Future<void> updateNotificationAPICall(int index) async {
|
||||||
|
var response = await http.put(
|
||||||
|
Uri.parse(
|
||||||
|
"$baseAPI/notifications/update/${widget.notifications[index].idnotifications}"),
|
||||||
|
);
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
Navigator.of(context).pushNamed(
|
||||||
|
"/",
|
||||||
|
);
|
||||||
|
Navigator.of(context).pushNamed(
|
||||||
|
widget.notifications[index].action_path,
|
||||||
|
arguments: widget.signedInUser,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
internetConnectionPopUp();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void internetConnectionPopUp() {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
return const MIHErrorMessage(errorType: "Internet Connection");
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
List<List<String>> setTempNofitications() {
|
List<List<String>> setTempNofitications() {
|
||||||
List<List<String>> temp = [];
|
List<List<String>> temp = [];
|
||||||
@@ -52,9 +84,7 @@ class _MIHNotificationDrawerState extends State<MIHNotificationDrawer> {
|
|||||||
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
onTap: () {
|
onTap: () {},
|
||||||
//viewApprovalPopUp(index);
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,7 +95,10 @@ class _MIHNotificationDrawerState extends State<MIHNotificationDrawer> {
|
|||||||
if (widget.notifications[index].notification_read == "No") {
|
if (widget.notifications[index].notification_read == "No") {
|
||||||
notificationTitle = Row(
|
notificationTitle = Row(
|
||||||
children: [
|
children: [
|
||||||
const Icon(Icons.circle_notifications),
|
Icon(
|
||||||
|
Icons.circle_notifications,
|
||||||
|
color: MzanziInnovationHub.of(context)!.theme.errorColor(),
|
||||||
|
),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
width: 5,
|
width: 5,
|
||||||
),
|
),
|
||||||
@@ -103,10 +136,14 @@ class _MIHNotificationDrawerState extends State<MIHNotificationDrawer> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.of(context).pushNamed(
|
if (widget.notifications[index].notification_read == "No") {
|
||||||
widget.notifications[index].action_path,
|
updateNotificationAPICall(index);
|
||||||
arguments: widget.signedInUser,
|
} else {
|
||||||
);
|
Navigator.of(context).pushNamed(
|
||||||
|
widget.notifications[index].action_path,
|
||||||
|
arguments: widget.signedInUser,
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user