mirror of
https://github.com/Iconica-Development/flutter_notification_center.git
synced 2025-05-18 16:43:44 +02:00
feat: put in snackbar
This commit is contained in:
parent
f9e7728412
commit
49c2418467
4 changed files with 134 additions and 3 deletions
|
@ -1,4 +1,5 @@
|
|||
import 'package:example/custom_notification.dart';
|
||||
import 'package:flutter_notification_center/src/notification_dialog.dart';
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
@ -55,9 +56,19 @@ class _NotificationCenterDemoState extends State<NotificationCenterDemo> {
|
|||
Widget build(BuildContext context) {
|
||||
var service = FirebaseNotificationService(
|
||||
newNotificationCallback: (notification) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => Dialog(child: Text(notification.title)));
|
||||
ScaffoldMessenger.of(context).showSnackBar(NotificationSnackbarWidget(
|
||||
title: notification.title,
|
||||
body: notification.body,
|
||||
datetimePublished: DateTime.now(),
|
||||
));
|
||||
|
||||
// showDialog(
|
||||
// context: context,
|
||||
// builder: (context) => NotificationDialog(
|
||||
// title: notification.title,
|
||||
// body: notification.body,
|
||||
// datetimePublished: notification.dateTimePushed),
|
||||
// );
|
||||
debugPrint('New notification: ${notification.title}');
|
||||
},
|
||||
);
|
||||
|
|
|
@ -7,6 +7,8 @@ export "src/models/notification_config.dart";
|
|||
export "src/models/notification_theme.dart";
|
||||
export "src/models/notification_translation.dart";
|
||||
export "src/notification_bell.dart";
|
||||
export "src/notification_dialog.dart";
|
||||
export "src/notification_snackbar.dart";
|
||||
export "src/notification_detail.dart";
|
||||
export "src/notification_bell_story.dart";
|
||||
export "src/notification_center.dart";
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class NotificationDialog extends StatelessWidget {
|
||||
final String title;
|
||||
final String body;
|
||||
final DateTime? datetimePublished;
|
||||
|
||||
const NotificationDialog({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.body,
|
||||
this.datetimePublished,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
String formattedDateTime = datetimePublished != null
|
||||
? DateFormat('dd MMM HH:mm').format(datetimePublished!)
|
||||
: 'N/A';
|
||||
|
||||
return AlertDialog(
|
||||
title: Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 20.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
content: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
body,
|
||||
style: const TextStyle(
|
||||
fontSize: 16.0,
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
formattedDateTime,
|
||||
style: const TextStyle(
|
||||
fontSize: 16.0,
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: const Text(
|
||||
'Dismiss',
|
||||
style: TextStyle(
|
||||
color: Colors.red,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class NotificationSnackbarWidget extends SnackBar {
|
||||
NotificationSnackbarWidget({
|
||||
super.key,
|
||||
required String title,
|
||||
required String body,
|
||||
DateTime? datetimePublished,
|
||||
}) : super(
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 20.0,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
body,
|
||||
style: const TextStyle(
|
||||
fontSize: 16.0,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
datetimePublished != null
|
||||
? DateFormat('dd MMM HH:mm').format(datetimePublished)
|
||||
: 'N/A',
|
||||
style: const TextStyle(
|
||||
fontSize: 12.0,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
backgroundColor: Colors.grey.shade700,
|
||||
duration: const Duration(seconds: 8),
|
||||
action: SnackBarAction(
|
||||
label: 'Dismiss',
|
||||
onPressed: () {},
|
||||
textColor: Colors.white,
|
||||
),
|
||||
);
|
||||
}
|
Loading…
Reference in a new issue