mirror of
https://github.com/Iconica-Development/flutter_notification_center.git
synced 2025-05-18 16:43:44 +02:00
fix: default style
This commit is contained in:
parent
169228152e
commit
91621bde96
8 changed files with 32 additions and 101 deletions
|
@ -6,7 +6,6 @@ export "package:flutter_animated_widgets/flutter_animated_widgets.dart";
|
|||
|
||||
export "src/models/notification.dart";
|
||||
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_bell_story.dart";
|
||||
|
|
|
@ -17,6 +17,8 @@ class NotificationConfig {
|
|||
this.showAsSnackBar = true,
|
||||
this.enableNotificationPopups = true,
|
||||
this.bellStyle = const AnimatedNotificationBellStyle(),
|
||||
this.pinnedIconColor = Colors.black,
|
||||
this.emptyNotificationsBuilder,
|
||||
});
|
||||
|
||||
/// The notification service to use for delivering notifications.
|
||||
|
@ -38,4 +40,10 @@ class NotificationConfig {
|
|||
|
||||
/// The style of the notification bell.
|
||||
final AnimatedNotificationBellStyle bellStyle;
|
||||
|
||||
/// The color of the trailing icon (if any) in the notification.
|
||||
final Color? pinnedIconColor;
|
||||
|
||||
/// A builder function to display when there are no notifications.
|
||||
final Widget Function()? emptyNotificationsBuilder;
|
||||
}
|
||||
|
|
|
@ -1,71 +0,0 @@
|
|||
import "package:flutter/material.dart";
|
||||
|
||||
/// Defines the appearance customization for notifications.
|
||||
class NotificationStyle {
|
||||
/// Creates a new [NotificationStyle] instance.
|
||||
///
|
||||
/// Each parameter is optional and allows customizing various aspects
|
||||
/// of the notification appearance.
|
||||
const NotificationStyle({
|
||||
this.titleTextStyle,
|
||||
this.subtitleTextStyle,
|
||||
this.backgroundColor,
|
||||
this.leadingIconColor,
|
||||
this.pinnedIconColor,
|
||||
this.contentPadding,
|
||||
this.titleTextAlign,
|
||||
this.subtitleTextAlign,
|
||||
this.dense,
|
||||
this.tileDecoration,
|
||||
this.emptyNotificationsBuilder,
|
||||
this.appTitleTextStyle,
|
||||
this.dividerColor,
|
||||
this.isReadDotColor,
|
||||
this.showNotificationIcon,
|
||||
});
|
||||
|
||||
/// The text style for the title of the notification.
|
||||
final TextStyle? titleTextStyle;
|
||||
|
||||
/// The text style for the subtitle of the notification.
|
||||
final TextStyle? subtitleTextStyle;
|
||||
|
||||
/// The background color of the notification.
|
||||
final Color? backgroundColor;
|
||||
|
||||
/// The color of the leading icon (if any) in the notification.
|
||||
final Color? leadingIconColor;
|
||||
|
||||
/// The color of the trailing icon (if any) in the notification.
|
||||
final Color? pinnedIconColor;
|
||||
|
||||
/// The padding around the content of the notification.
|
||||
final EdgeInsets? contentPadding;
|
||||
|
||||
/// The alignment of the title text within the notification.
|
||||
final TextAlign? titleTextAlign;
|
||||
|
||||
/// The alignment of the subtitle text within the notification.
|
||||
final TextAlign? subtitleTextAlign;
|
||||
|
||||
/// Whether the notification should be dense or not.
|
||||
final bool? dense;
|
||||
|
||||
/// The decoration to apply to the tile of the notification.
|
||||
final BoxDecoration? tileDecoration;
|
||||
|
||||
/// A builder function to display when there are no notifications.
|
||||
final Widget Function()? emptyNotificationsBuilder;
|
||||
|
||||
/// The text style for the application title.
|
||||
final TextStyle? appTitleTextStyle;
|
||||
|
||||
/// The color of the divider.
|
||||
final Color? dividerColor;
|
||||
|
||||
/// The color of the dot that shows that anotification has not been read.
|
||||
final Color? isReadDotColor;
|
||||
|
||||
/// Whether to show the notification icon.
|
||||
final bool? showNotificationIcon;
|
||||
}
|
|
@ -14,7 +14,7 @@ class NotificationTranslations {
|
|||
});
|
||||
|
||||
const NotificationTranslations.empty({
|
||||
this.appBarTitle = "Notifications",
|
||||
this.appBarTitle = "notifications",
|
||||
this.noNotifications = "No unread notifications available.",
|
||||
this.notificationDismissed = "Notification dismissed.",
|
||||
this.notificationPinned = "Notification pinned.",
|
||||
|
|
|
@ -46,6 +46,7 @@ class _NotificationBellState extends State<NotificationBell> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) => IconButton(
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: widget.onTap,
|
||||
icon: AnimatedNotificationBell(
|
||||
duration: const Duration(seconds: 1),
|
||||
|
|
|
@ -48,12 +48,11 @@ class NotificationCenterState extends State<NotificationCenter> {
|
|||
Widget build(BuildContext context) {
|
||||
var theme = Theme.of(context);
|
||||
return Scaffold(
|
||||
backgroundColor: theme.colorScheme.surface,
|
||||
appBar: AppBar(
|
||||
backgroundColor: theme.appBarTheme.backgroundColor,
|
||||
title: Text(
|
||||
widget.config.translations.appBarTitle,
|
||||
style: theme.appBarTheme.titleTextStyle,
|
||||
style: theme.textTheme.headlineLarge,
|
||||
),
|
||||
centerTitle: true,
|
||||
iconTheme: theme.appBarTheme.iconTheme ??
|
||||
|
@ -76,9 +75,13 @@ class NotificationCenterState extends State<NotificationCenter> {
|
|||
debugPrint("Error: ${snapshot.error}");
|
||||
return Center(child: Text(widget.config.translations.errorMessage));
|
||||
} else if (snapshot.data == null || snapshot.data!.isEmpty) {
|
||||
return Center(
|
||||
child: Text(widget.config.translations.noNotifications),
|
||||
);
|
||||
return widget.config.emptyNotificationsBuilder?.call() ??
|
||||
Center(
|
||||
child: Text(
|
||||
widget.config.translations.noNotifications,
|
||||
style: theme.textTheme.bodyMedium,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
|
@ -95,7 +98,6 @@ class NotificationCenterState extends State<NotificationCenter> {
|
|||
notification,
|
||||
widget.config.service,
|
||||
widget.config.translations,
|
||||
const NotificationStyle(),
|
||||
),
|
||||
child: Dismissible(
|
||||
key: Key("${notification.id}_pinned"),
|
||||
|
@ -154,6 +156,7 @@ class NotificationCenterState extends State<NotificationCenter> {
|
|||
child: _notificationItem(
|
||||
context,
|
||||
notification,
|
||||
widget.config,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
@ -163,7 +166,6 @@ class NotificationCenterState extends State<NotificationCenter> {
|
|||
notification,
|
||||
widget.config.service,
|
||||
widget.config.translations,
|
||||
const NotificationStyle(),
|
||||
),
|
||||
child: Dismissible(
|
||||
key: Key(notification.id),
|
||||
|
@ -225,6 +227,7 @@ class NotificationCenterState extends State<NotificationCenter> {
|
|||
child: _notificationItem(
|
||||
context,
|
||||
notification,
|
||||
widget.config,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
@ -240,6 +243,7 @@ class NotificationCenterState extends State<NotificationCenter> {
|
|||
Widget _notificationItem(
|
||||
BuildContext context,
|
||||
NotificationModel notification,
|
||||
NotificationConfig config,
|
||||
) {
|
||||
var theme = Theme.of(context);
|
||||
var dateTimePushed =
|
||||
|
@ -267,7 +271,7 @@ Widget _notificationItem(
|
|||
const Icon(
|
||||
Icons.circle_rounded,
|
||||
color: Colors.black,
|
||||
size: 10,
|
||||
size: 8,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 8,
|
||||
|
@ -283,7 +287,7 @@ Widget _notificationItem(
|
|||
notification.isRead
|
||||
? Icons.push_pin_outlined
|
||||
: Icons.push_pin,
|
||||
color: Colors.black,
|
||||
color: config.pinnedIconColor,
|
||||
size: 30,
|
||||
),
|
||||
),
|
||||
|
@ -293,15 +297,15 @@ Widget _notificationItem(
|
|||
],
|
||||
Text(
|
||||
notification.title,
|
||||
style: notification.isRead
|
||||
style: notification.isRead && !notification.isPinned
|
||||
? theme.textTheme.bodyMedium
|
||||
: theme.textTheme.bodyLarge,
|
||||
: theme.textTheme.titleMedium,
|
||||
),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
dateTimePushed,
|
||||
style: theme.textTheme.bodyMedium,
|
||||
style: theme.textTheme.labelSmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
@ -315,7 +319,6 @@ Future<void> _navigateToNotificationDetail(
|
|||
NotificationModel notification,
|
||||
NotificationService notificationService,
|
||||
NotificationTranslations notificationTranslations,
|
||||
NotificationStyle style,
|
||||
) async {
|
||||
if (context.mounted) {
|
||||
await Navigator.push(
|
||||
|
@ -324,7 +327,6 @@ Future<void> _navigateToNotificationDetail(
|
|||
builder: (context) => NotificationDetailPage(
|
||||
translations: notificationTranslations,
|
||||
notification: notification,
|
||||
notificationStyle: style,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
|
@ -11,15 +11,11 @@ class NotificationDetailPage extends StatelessWidget {
|
|||
/// The [notification] parameter specifies the notification
|
||||
/// to display details for.
|
||||
const NotificationDetailPage({
|
||||
required this.notificationStyle,
|
||||
required this.notification,
|
||||
required this.translations,
|
||||
super.key,
|
||||
});
|
||||
|
||||
/// The notification style.
|
||||
final NotificationStyle notificationStyle;
|
||||
|
||||
/// The notification to display details for.
|
||||
final NotificationModel notification;
|
||||
|
||||
|
@ -30,12 +26,11 @@ class NotificationDetailPage extends StatelessWidget {
|
|||
Widget build(BuildContext context) {
|
||||
var theme = Theme.of(context);
|
||||
return Scaffold(
|
||||
backgroundColor: theme.colorScheme.surface,
|
||||
appBar: AppBar(
|
||||
backgroundColor: theme.appBarTheme.backgroundColor,
|
||||
title: Text(
|
||||
translations.appBarTitle,
|
||||
style: theme.appBarTheme.titleTextStyle,
|
||||
style: theme.textTheme.headlineLarge,
|
||||
),
|
||||
iconTheme: theme.appBarTheme.iconTheme ??
|
||||
const IconThemeData(color: Colors.white),
|
||||
|
@ -57,12 +52,12 @@ class NotificationDetailPage extends StatelessWidget {
|
|||
children: [
|
||||
Text(
|
||||
notification.title,
|
||||
style: notificationStyle.titleTextStyle ?? const TextStyle(),
|
||||
style: theme.textTheme.titleMedium,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
notification.body,
|
||||
style: notificationStyle.subtitleTextStyle ?? const TextStyle(),
|
||||
style: theme.textTheme.bodyMedium,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
|
@ -70,10 +65,7 @@ class NotificationDetailPage extends StatelessWidget {
|
|||
' ${DateFormat('yyyy-MM-dd HH:mm').format(
|
||||
notification.dateTimePushed ?? DateTime.now(),
|
||||
)}',
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.grey,
|
||||
),
|
||||
style: theme.textTheme.labelSmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
name: flutter_notification_center
|
||||
description: "A Flutter package for displaying notifications in a notification center."
|
||||
publish_to: "none"
|
||||
version: 2.0.0
|
||||
version: 3.0.0
|
||||
|
||||
environment:
|
||||
sdk: ">=3.3.2 <4.0.0"
|
||||
|
@ -14,7 +14,7 @@ dependencies:
|
|||
flutter_animated_widgets:
|
||||
git:
|
||||
url: https://github.com/Iconica-Development/flutter_animated_widgets
|
||||
ref: 0.3.0
|
||||
ref: 0.3.1
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
Loading…
Reference in a new issue