Home screen pop notification pt2

This commit is contained in:
2024-10-08 13:25:01 +02:00
parent c7b1b72783
commit 16f92d5579
3 changed files with 108 additions and 105 deletions

View File

@@ -25,6 +25,8 @@ class _MIHNotificationMessageState extends State<MIHNotificationMessage>
late double popUpBodySize; late double popUpBodySize;
late double popUpIconSize; late double popUpIconSize;
late double popUpPaddingSize; late double popUpPaddingSize;
late Color primary;
late Color secondary;
Size? size; Size? size;
void checkScreenSize() { void checkScreenSize() {
@@ -35,105 +37,87 @@ class _MIHNotificationMessageState extends State<MIHNotificationMessage>
popUpTitleSize = 20.0; popUpTitleSize = 20.0;
popUpSubtitleSize = 20.0; popUpSubtitleSize = 20.0;
popUpBodySize = 15; popUpBodySize = 15;
popUpPaddingSize = 5.0; popUpPaddingSize = 25.0;
popUpIconSize = 100; popUpIconSize = 100;
}); });
} else { } else {
setState(() { setState(() {
popUpWidth = size!.width - 20; popUpWidth = size!.width;
popUpheight = 90; popUpheight = 90;
popUpTitleSize = 20.0; popUpTitleSize = 20.0;
popUpSubtitleSize = 18.0; popUpSubtitleSize = 18.0;
popUpBodySize = 15; popUpBodySize = 15;
popUpPaddingSize = 15.0; popUpPaddingSize = 5.0;
popUpIconSize = 100; popUpIconSize = 100;
}); });
} }
} }
Widget NotifyPopUp() { Widget notifyPopUp() {
//messageTypes["Input Error"] = //messageTypes["Input Error"] =
return Stack( return GestureDetector(
children: [ onTap: widget.arguments.onTap,
Container( child: Container(
padding: EdgeInsets.all(popUpPaddingSize), padding:
alignment: Alignment.topLeft, EdgeInsets.symmetric(vertical: 5, horizontal: popUpPaddingSize),
width: popUpWidth, alignment: Alignment.topLeft,
height: popUpheight, width: popUpWidth,
decoration: BoxDecoration( height: popUpheight,
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), decoration: BoxDecoration(
borderRadius: BorderRadius.circular(25.0), color: primary,
// border: Border.all( borderRadius: BorderRadius.circular(25.0),
// color: MzanziInnovationHub.of(context)!.theme.primaryColor(), border: Border.all(color: secondary, width: 5.0),
// width: 5.0), ),
), child: Column(
child: SingleChildScrollView( // crossAxisAlignment: CrossAxisAlignment.start,
child: Column( // mainAxisAlignment: MainAxisAlignment.start,
// crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.max,
// mainAxisAlignment: MainAxisAlignment.start, children: [
mainAxisSize: MainAxisSize.max, //const SizedBox(height: 5),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
//const SizedBox(height: 5), Icon(
Row( Icons.notifications,
children: [ color: secondary,
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), const SizedBox(width: 10),
Row( Flexible(
children: [ child: Text(
Text( widget.arguments.title,
widget.arguments.body, textAlign: TextAlign.center,
textAlign: TextAlign.left, overflow: TextOverflow.ellipsis,
style: TextStyle( style: TextStyle(
color: MzanziInnovationHub.of(context)! color: secondary,
.theme fontSize: popUpTitleSize,
.primaryColor(), fontWeight: FontWeight.bold,
fontSize: popUpBodySize,
fontWeight: FontWeight.bold,
),
), ),
], ),
), ),
], ],
), ),
), const SizedBox(height: 5),
), Wrap(
Positioned( alignment: WrapAlignment.start,
top: 5, children: [
right: 5, SizedBox(
width: 50, width: popUpWidth,
height: 50, child: Text(
child: IconButton( widget.arguments.body,
onPressed: () { textAlign: TextAlign.left,
Navigator.pop(context); overflow: TextOverflow.ellipsis,
}, style: TextStyle(
icon: Icon( color: secondary,
Icons.close, fontSize: popUpBodySize,
color: MzanziInnovationHub.of(context)!.theme.errorColor(), fontWeight: FontWeight.bold,
size: 35, ),
),
),
],
), ),
), ],
), ),
], ),
); );
} }
@@ -146,11 +130,14 @@ class _MIHNotificationMessageState extends State<MIHNotificationMessage>
@override @override
void initState() { void initState() {
super.initState(); super.initState();
setState(() {
primary = MzanziInnovationHub.of(context)!.theme.primaryColor();
secondary = MzanziInnovationHub.of(context)!.theme.secondaryColor();
});
_animationController = AnimationController( _animationController = AnimationController(
vsync: this, vsync: this,
duration: duration:
const Duration(milliseconds: 200), // Adjust the duration as needed const Duration(milliseconds: 300), // Adjust the duration as needed
); );
_scaleAnimation = Tween<Offset>( _scaleAnimation = Tween<Offset>(
@@ -177,10 +164,9 @@ class _MIHNotificationMessageState extends State<MIHNotificationMessage>
return SlideTransition( return SlideTransition(
position: _scaleAnimation, position: _scaleAnimation,
child: Dialog( child: Dialog(
insetAnimationDuration: const Duration(milliseconds: 1000), shadowColor: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
insetAnimationCurve: Curves.bounceIn,
alignment: Alignment.topCenter, alignment: Alignment.topCenter,
child: NotifyPopUp(), child: notifyPopUp(),
), ),
); );
// return SlideTransition( // return SlideTransition(

View File

@@ -10,10 +10,12 @@ import 'package:patient_manager/mih_objects/patients.dart';
class NotificationArguments { class NotificationArguments {
final String title; final String title;
final String body; final String body;
final void Function()? onTap;
NotificationArguments( NotificationArguments(
this.title, this.title,
this.body, this.body,
this.onTap,
); );
} }

View File

@@ -247,12 +247,18 @@ class _MIHHomeState extends State<MIHHome> {
barrierColor: const Color(0x01000000), barrierColor: const Color(0x01000000),
context: context, context: context,
builder: (context) { builder: (context) {
return MIHNotificationMessage( return Builder(builder: (context) {
arguments: NotificationArguments( return MIHNotificationMessage(
"Testing", arguments: NotificationArguments(
"Testing the new MIH Notification", "Testing",
), "Testing the new MIH Notification",
); () {
Navigator.of(context).pop();
//Scaffold.of(context).openEndDrawer();
},
),
);
});
}, },
); );
}, },
@@ -733,6 +739,7 @@ class _MIHHomeState extends State<MIHHome> {
//print(widget.notifications.toString()); //print(widget.notifications.toString());
if (notifiList.map((item) => item.notification_read).contains("No")) { if (notifiList.map((item) => item.notification_read).contains("No")) {
//print("New Notification Available"); //print("New Notification Available");
return true; return true;
} else { } else {
//print("No New Notification Available"); //print("No New Notification Available");
@@ -760,25 +767,30 @@ class _MIHHomeState extends State<MIHHome> {
setState(() { setState(() {
notifiList = notifi; notifiList = notifi;
}); });
notificationPopUp();
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() { void notificationPopUp() {
showDialog( if (hasNewNotifications()) {
context: context, showDialog(
builder: (context) { barrierColor: const Color(0x01000000),
return const MIHErrorMessage(errorType: "Internet Connection"); context: context,
}, builder: (context) {
); return Builder(builder: (context) {
return MIHNotificationMessage(
arguments: NotificationArguments(
"Unread Notification",
"You have unread notifications waiting for you.",
() {
Navigator.of(context).pop();
//Scaffold.of(context).openEndDrawer();
},
),
);
});
},
);
}
} }
@override @override
@@ -790,12 +802,15 @@ class _MIHHomeState extends State<MIHHome> {
@override @override
void initState() { void initState() {
super.initState();
setState(() { setState(() {
pbswitch = setApps(persHTList, busHTList); pbswitch = setApps(persHTList, busHTList);
businessUserSwitch = false; businessUserSwitch = false;
notifiList = widget.notifications; notifiList = widget.notifications;
}); });
super.initState(); WidgetsBinding.instance.addPostFrameCallback((_) {
notificationPopUp();
});
} }
@override @override