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,39 +37,37 @@ 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:
EdgeInsets.symmetric(vertical: 5, horizontal: popUpPaddingSize),
alignment: Alignment.topLeft, alignment: Alignment.topLeft,
width: popUpWidth, width: popUpWidth,
height: popUpheight, height: popUpheight,
decoration: BoxDecoration( decoration: BoxDecoration(
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), color: primary,
borderRadius: BorderRadius.circular(25.0), borderRadius: BorderRadius.circular(25.0),
// border: Border.all( border: Border.all(color: secondary, width: 5.0),
// color: MzanziInnovationHub.of(context)!.theme.primaryColor(),
// width: 5.0),
), ),
child: SingleChildScrollView(
child: Column( child: Column(
// crossAxisAlignment: CrossAxisAlignment.start, // crossAxisAlignment: CrossAxisAlignment.start,
// mainAxisAlignment: MainAxisAlignment.start, // mainAxisAlignment: MainAxisAlignment.start,
@@ -75,21 +75,20 @@ class _MIHNotificationMessageState extends State<MIHNotificationMessage>
children: [ children: [
//const SizedBox(height: 5), //const SizedBox(height: 5),
Row( Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Icon( Icon(
Icons.notifications, Icons.notifications,
color: color: secondary,
MzanziInnovationHub.of(context)!.theme.primaryColor(),
), ),
const SizedBox(width: 10),
Flexible( Flexible(
child: Text( child: Text(
widget.arguments.title, widget.arguments.title,
textAlign: TextAlign.left, textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
style: TextStyle( style: TextStyle(
color: MzanziInnovationHub.of(context)! color: secondary,
.theme
.primaryColor(),
fontSize: popUpTitleSize, fontSize: popUpTitleSize,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
@@ -98,42 +97,27 @@ class _MIHNotificationMessageState extends State<MIHNotificationMessage>
], ],
), ),
const SizedBox(height: 5), const SizedBox(height: 5),
Row( Wrap(
alignment: WrapAlignment.start,
children: [ children: [
Text( SizedBox(
width: popUpWidth,
child: Text(
widget.arguments.body, widget.arguments.body,
textAlign: TextAlign.left, textAlign: TextAlign.left,
overflow: TextOverflow.ellipsis,
style: TextStyle( style: TextStyle(
color: MzanziInnovationHub.of(context)! color: secondary,
.theme
.primaryColor(),
fontSize: popUpBodySize, fontSize: popUpBodySize,
fontWeight: FontWeight.bold, 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,
),
),
),
],
); );
} }
@@ -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 Builder(builder: (context) {
return MIHNotificationMessage( return MIHNotificationMessage(
arguments: NotificationArguments( arguments: NotificationArguments(
"Testing", "Testing",
"Testing the new MIH Notification", "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,26 +767,31 @@ class _MIHHomeState extends State<MIHHome> {
setState(() { setState(() {
notifiList = notifi; 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(); notificationPopUp();
} }
}
void notificationPopUp() { void notificationPopUp() {
if (hasNewNotifications()) {
showDialog( showDialog(
barrierColor: const Color(0x01000000),
context: context, context: context,
builder: (context) { builder: (context) {
return const MIHErrorMessage(errorType: "Internet Connection"); 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
void dispose() { void dispose() {
@@ -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