forked from yaso_meth/mih-project
Pop up notification pt1
This commit is contained in:
BIN
Frontend/patient_manager/images/notify_logo.png
Normal file
BIN
Frontend/patient_manager/images/notify_logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 54 KiB |
@@ -0,0 +1,197 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:patient_manager/main.dart';
|
||||
import 'package:patient_manager/mih_objects/arguments.dart';
|
||||
|
||||
class MIHNotificationMessage extends StatefulWidget {
|
||||
final NotificationArguments arguments;
|
||||
const MIHNotificationMessage({
|
||||
super.key,
|
||||
required this.arguments,
|
||||
});
|
||||
|
||||
@override
|
||||
State<MIHNotificationMessage> createState() => _MIHNotificationMessageState();
|
||||
}
|
||||
|
||||
class _MIHNotificationMessageState extends State<MIHNotificationMessage>
|
||||
with SingleTickerProviderStateMixin {
|
||||
//var messageTypes = <String, Widget>{};
|
||||
late AnimationController _animationController;
|
||||
late Animation<Offset> _scaleAnimation;
|
||||
late double popUpWidth;
|
||||
late double? popUpheight;
|
||||
late double popUpTitleSize;
|
||||
late double popUpSubtitleSize;
|
||||
late double popUpBodySize;
|
||||
late double popUpIconSize;
|
||||
late double popUpPaddingSize;
|
||||
Size? size;
|
||||
|
||||
void checkScreenSize() {
|
||||
if (MzanziInnovationHub.of(context)!.theme.screenType == "desktop") {
|
||||
setState(() {
|
||||
popUpWidth = (size!.width / 4) * 2;
|
||||
popUpheight = 90;
|
||||
popUpTitleSize = 20.0;
|
||||
popUpSubtitleSize = 20.0;
|
||||
popUpBodySize = 15;
|
||||
popUpPaddingSize = 5.0;
|
||||
popUpIconSize = 100;
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
popUpWidth = size!.width - 20;
|
||||
popUpheight = 90;
|
||||
popUpTitleSize = 20.0;
|
||||
popUpSubtitleSize = 18.0;
|
||||
popUpBodySize = 15;
|
||||
popUpPaddingSize = 15.0;
|
||||
popUpIconSize = 100;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Widget NotifyPopUp() {
|
||||
//messageTypes["Input Error"] =
|
||||
return Stack(
|
||||
children: [
|
||||
Container(
|
||||
padding: EdgeInsets.all(popUpPaddingSize),
|
||||
alignment: Alignment.topLeft,
|
||||
width: popUpWidth,
|
||||
height: popUpheight,
|
||||
decoration: BoxDecoration(
|
||||
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
borderRadius: BorderRadius.circular(25.0),
|
||||
// border: Border.all(
|
||||
// color: MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||
// width: 5.0),
|
||||
),
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
// crossAxisAlignment: CrossAxisAlignment.start,
|
||||
// mainAxisAlignment: MainAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
//const SizedBox(height: 5),
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.notifications,
|
||||
color:
|
||||
MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||
),
|
||||
Flexible(
|
||||
child: Text(
|
||||
widget.arguments.title,
|
||||
textAlign: TextAlign.left,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
color: MzanziInnovationHub.of(context)!
|
||||
.theme
|
||||
.primaryColor(),
|
||||
fontSize: popUpTitleSize,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
widget.arguments.body,
|
||||
textAlign: TextAlign.left,
|
||||
style: TextStyle(
|
||||
color: MzanziInnovationHub.of(context)!
|
||||
.theme
|
||||
.primaryColor(),
|
||||
fontSize: popUpBodySize,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
top: 5,
|
||||
right: 5,
|
||||
width: 50,
|
||||
height: 50,
|
||||
child: IconButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
icon: Icon(
|
||||
Icons.close,
|
||||
color: MzanziInnovationHub.of(context)!.theme.errorColor(),
|
||||
size: 35,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_animationController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_animationController = AnimationController(
|
||||
vsync: this,
|
||||
duration:
|
||||
const Duration(milliseconds: 200), // Adjust the duration as needed
|
||||
);
|
||||
|
||||
_scaleAnimation = Tween<Offset>(
|
||||
begin: const Offset(0, -1),
|
||||
end: Offset.zero,
|
||||
).animate(_animationController);
|
||||
|
||||
// Start the animation when
|
||||
// the dialog is displayed
|
||||
_animationController.forward();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
size = MediaQuery.of(context).size;
|
||||
checkScreenSize();
|
||||
//setInputError();
|
||||
|
||||
//print(size);
|
||||
// setState(() {
|
||||
// width = size.width;
|
||||
// height = size.height;
|
||||
// });
|
||||
return SlideTransition(
|
||||
position: _scaleAnimation,
|
||||
child: Dialog(
|
||||
insetAnimationDuration: const Duration(milliseconds: 1000),
|
||||
insetAnimationCurve: Curves.bounceIn,
|
||||
alignment: Alignment.topCenter,
|
||||
child: NotifyPopUp(),
|
||||
),
|
||||
);
|
||||
// return SlideTransition(
|
||||
// position: Tween<Offset>(
|
||||
// begin: const Offset(0, -1),
|
||||
// end: Offset.zero,
|
||||
// ).animate(widget.animationController),
|
||||
// child: Dialog(
|
||||
// alignment: Alignment.topCenter,
|
||||
// child: NotifyPopUp(),
|
||||
// ),
|
||||
// );
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,16 @@ import 'package:patient_manager/mih_objects/business_user.dart';
|
||||
import 'package:patient_manager/mih_objects/notification.dart';
|
||||
import 'package:patient_manager/mih_objects/patients.dart';
|
||||
|
||||
class NotificationArguments {
|
||||
final String title;
|
||||
final String body;
|
||||
|
||||
NotificationArguments(
|
||||
this.title,
|
||||
this.body,
|
||||
);
|
||||
}
|
||||
|
||||
class BusinessArguments {
|
||||
final AppUser signedInUser;
|
||||
final BusinessUser? businessUser;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -14,6 +15,7 @@ import 'package:patient_manager/mih_components/mih_layout/mih_app_drawer.dart';
|
||||
import 'package:patient_manager/mih_components/mih_layout/mih_window.dart';
|
||||
import 'package:patient_manager/mih_components/mih_pop_up_messages/mih_delete_message.dart';
|
||||
import 'package:patient_manager/mih_components/mih_pop_up_messages/mih_loading_circle.dart';
|
||||
import 'package:patient_manager/mih_components/mih_pop_up_messages/mih_notification_message.dart';
|
||||
import 'package:patient_manager/mih_components/mih_pop_up_messages/mih_warning_message.dart';
|
||||
import 'package:patient_manager/mih_components/mih_pop_up_messages/mih_error_message.dart';
|
||||
import 'package:patient_manager/mih_components/mih_pop_up_messages/mih_success_message.dart';
|
||||
@@ -239,6 +241,30 @@ class _MIHHomeState extends State<MIHHome> {
|
||||
|
||||
void setAppsDev(List<MIHTile> tileList) {
|
||||
if (AppEnviroment.getEnv() == "Dev") {
|
||||
tileList.add(MIHTile(
|
||||
onTap: () {
|
||||
showDialog(
|
||||
barrierColor: const Color(0x01000000),
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return MIHNotificationMessage(
|
||||
arguments: NotificationArguments(
|
||||
"Testing",
|
||||
"Testing the new MIH Notification",
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
tileName: "Notify - Dev",
|
||||
tileIcon: Icon(
|
||||
Icons.notifications,
|
||||
color: getSec(),
|
||||
size: 200,
|
||||
),
|
||||
p: getPrim(),
|
||||
s: getSec(),
|
||||
));
|
||||
tileList.add(MIHTile(
|
||||
onTap: () {
|
||||
showDialog(
|
||||
@@ -705,9 +731,7 @@ class _MIHHomeState extends State<MIHHome> {
|
||||
|
||||
bool hasNewNotifications() {
|
||||
//print(widget.notifications.toString());
|
||||
if (widget.notifications
|
||||
.map((item) => item.notification_read)
|
||||
.contains("No")) {
|
||||
if (notifiList.map((item) => item.notification_read).contains("No")) {
|
||||
//print("New Notification Available");
|
||||
return true;
|
||||
} else {
|
||||
@@ -736,6 +760,25 @@ class _MIHHomeState extends State<MIHHome> {
|
||||
setState(() {
|
||||
notifiList = notifi;
|
||||
});
|
||||
|
||||
if (hasNewNotifications()) {
|
||||
print("New Notifications");
|
||||
// await MIHNotificationServices.showNotification(
|
||||
// title: "New Notification waiting",
|
||||
// body:
|
||||
// "You have new notification waiting for you in the notification panel",
|
||||
// );
|
||||
notificationPopUp();
|
||||
}
|
||||
}
|
||||
|
||||
void notificationPopUp() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return const MIHErrorMessage(errorType: "Internet Connection");
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -752,7 +795,6 @@ class _MIHHomeState extends State<MIHHome> {
|
||||
businessUserSwitch = false;
|
||||
notifiList = widget.notifications;
|
||||
});
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:patient_manager/mih_components/mih_layout/mih_print_prevew.dart';
|
||||
import 'package:patient_manager/mih_components/mih_pop_up_messages/mih_notification_message.dart';
|
||||
import 'package:patient_manager/mih_packages/authentication/auth_check.dart';
|
||||
import 'package:patient_manager/mih_packages/patient_profile/add_or_view_patient.dart';
|
||||
import 'package:patient_manager/mih_packages/patient_profile/patient_add.dart';
|
||||
@@ -40,6 +41,16 @@ class RouteGenerator {
|
||||
case '/':
|
||||
return MaterialPageRoute(
|
||||
settings: settings, builder: (_) => const AuthCheck());
|
||||
case '/notifications':
|
||||
if (args is NotificationArguments) {
|
||||
return MaterialPageRoute(
|
||||
settings: settings,
|
||||
builder: (_) => MIHNotificationMessage(
|
||||
arguments: args,
|
||||
),
|
||||
);
|
||||
}
|
||||
return _errorRoute();
|
||||
case '/forgot-password':
|
||||
return MaterialPageRoute(
|
||||
settings: settings, builder: (_) => const ForgotPassword());
|
||||
|
||||
Reference in New Issue
Block a user