From 0edad6b3a8f16b9e7ec9591358a2bc3cce190764 Mon Sep 17 00:00:00 2001 From: Jacques Date: Thu, 4 Apr 2024 11:11:00 +0200 Subject: [PATCH] feat: Add widget story for notification bell --- .dart_tool/extension_discovery/README.md | 31 ------- .dart_tool/extension_discovery/vs_code.json | 1 - .dart_tool/package_config.json | 8 +- .dart_tool/package_config_subset | 4 + example/lib/main.dart | 92 ++++++++++++--------- example/pubspec.lock | 10 +++ lib/flutter_notification_center.dart | 3 + lib/src/models/notification_config.dart | 14 ++++ lib/src/notification_bell.dart | 31 +++++++ lib/src/notification_bell_story.dart | 27 ++++++ lib/src/notification_center.dart | 29 +++---- pubspec.lock | 10 +++ pubspec.yaml | 4 + 13 files changed, 174 insertions(+), 90 deletions(-) delete mode 100644 .dart_tool/extension_discovery/README.md delete mode 100644 .dart_tool/extension_discovery/vs_code.json create mode 100644 lib/src/models/notification_config.dart create mode 100644 lib/src/notification_bell.dart create mode 100644 lib/src/notification_bell_story.dart diff --git a/.dart_tool/extension_discovery/README.md b/.dart_tool/extension_discovery/README.md deleted file mode 100644 index 9dc6757..0000000 --- a/.dart_tool/extension_discovery/README.md +++ /dev/null @@ -1,31 +0,0 @@ -Extension Discovery Cache -========================= - -This folder is used by `package:extension_discovery` to cache lists of -packages that contains extensions for other packages. - -DO NOT USE THIS FOLDER ----------------------- - - * Do not read (or rely) the contents of this folder. - * Do write to this folder. - -If you're interested in the lists of extensions stored in this folder use the -API offered by package `extension_discovery` to get this information. - -If this package doesn't work for your use-case, then don't try to read the -contents of this folder. It may change, and will not remain stable. - -Use package `extension_discovery` ---------------------------------- - -If you want to access information from this folder. - -Feel free to delete this folder -------------------------------- - -Files in this folder act as a cache, and the cache is discarded if the files -are older than the modification time of `.dart_tool/package_config.json`. - -Hence, it should never be necessary to clear this cache manually, if you find a -need to do please file a bug. diff --git a/.dart_tool/extension_discovery/vs_code.json b/.dart_tool/extension_discovery/vs_code.json deleted file mode 100644 index ddc1a0f..0000000 --- a/.dart_tool/extension_discovery/vs_code.json +++ /dev/null @@ -1 +0,0 @@ -{"version":2,"entries":[{"package":"flutter_notification_center","rootUri":"../","packageUri":"lib/"}]} \ No newline at end of file diff --git a/.dart_tool/package_config.json b/.dart_tool/package_config.json index 2340ed7..75a4e27 100644 --- a/.dart_tool/package_config.json +++ b/.dart_tool/package_config.json @@ -49,6 +49,12 @@ "packageUri": "lib/", "languageVersion": "3.2" }, + { + "name": "flutter_animated_widgets", + "rootUri": "file:///Users/jacquesdoeleman/.pub-cache/git/flutter_animated_widgets-0eb6ea4c2e64b757b468e23ee2055e27e8302397/", + "packageUri": "lib/", + "languageVersion": "2.18" + }, { "name": "flutter_lints", "rootUri": "file:///Users/jacquesdoeleman/.pub-cache/hosted/pub.dev/flutter_lints-3.0.2", @@ -176,7 +182,7 @@ "languageVersion": "3.3" } ], - "generated": "2024-04-03T12:50:20.344201Z", + "generated": "2024-04-04T07:46:25.501696Z", "generator": "pub", "generatorVersion": "3.3.3" } diff --git a/.dart_tool/package_config_subset b/.dart_tool/package_config_subset index f8451b3..d944a04 100644 --- a/.dart_tool/package_config_subset +++ b/.dart_tool/package_config_subset @@ -1,3 +1,7 @@ +flutter_animated_widgets +2.18 +file:///Users/jacquesdoeleman/.pub-cache/git/flutter_animated_widgets-0eb6ea4c2e64b757b468e23ee2055e27e8302397/ +file:///Users/jacquesdoeleman/.pub-cache/git/flutter_animated_widgets-0eb6ea4c2e64b757b468e23ee2055e27e8302397/lib/ async 2.18 file:///Users/jacquesdoeleman/.pub-cache/hosted/pub.dev/async-2.11.0/ diff --git a/example/lib/main.dart b/example/lib/main.dart index cd07b01..75e1e96 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -9,49 +9,63 @@ void main() { ); } -class NotificationCenterDemo extends StatelessWidget { +class NotificationCenterDemo extends StatefulWidget { const NotificationCenterDemo({Key? key}) : super(key: key); + @override + State createState() => _NotificationCenterDemoState(); +} + +class _NotificationCenterDemoState extends State { + var config = NotificationConfig( + service: NotificationService( + listOfNotifications: [ + NotificationModel( + title: 'Notification title 1', + body: 'Notification body 1', + dateTime: DateTime.now(), + isRead: false, + ), + NotificationModel( + title: 'RECURRING', + body: 'RECURRING', + dateTime: DateTime.now(), + isRead: false, + isScheduled: true, + ), + NotificationModel( + title: 'Notification title 2', + body: 'Notification body 2', + dateTime: DateTime.now(), + isRead: false, + ), + NotificationModel( + title: 'Notification title 3', + body: 'Notification body 3', + dateTime: DateTime.now(), + isRead: false, + ), + ], + ), + style: const NotificationStyle( + titleTextStyle: TextStyle(color: Colors.red, fontSize: 20), + subtitleTextStyle: TextStyle(color: Colors.blue, fontSize: 16), + subtitleTextAlign: TextAlign.end), + ); + @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar( - title: const Text('Notification Center'), - centerTitle: true, - ), - body: NotificationCenter( - key: key, - notificationCenterService: NotificationService(listOfNotifications: [ - NotificationModel( - title: 'Notification title 1', - body: 'Notification body 1', - dateTime: DateTime.now(), - isRead: false, - ), - NotificationModel( - title: 'RECURRING', - body: 'RECURRING', - dateTime: DateTime.now(), - isRead: false, - isScheduled: true, - ), - NotificationModel( - title: 'Notification title 2', - body: 'Notification body 2', - dateTime: DateTime.now(), - isRead: false, - ), - NotificationModel( - title: 'Notification title 3', - body: 'Notification body 3', - dateTime: DateTime.now(), - isRead: false, - ), - ]), - notificationTheme: const NotificationStyle( - titleTextStyle: TextStyle(color: Colors.red, fontSize: 20), - subtitleTextStyle: TextStyle(color: Colors.blue, fontSize: 16), - subtitleTextAlign: TextAlign.end), - )); + appBar: AppBar( + title: const Text('Notification Center Demo'), + centerTitle: true, + actions: [ + NotificationBellWidgetStory( + config: config, + ), + ], + ), + body: const SizedBox.shrink(), + ); } } diff --git a/example/pubspec.lock b/example/pubspec.lock index 4687940..e50bdcc 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -62,6 +62,15 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_animated_widgets: + dependency: transitive + description: + path: "." + ref: "0.0.1" + resolved-ref: "0eb6ea4c2e64b757b468e23ee2055e27e8302397" + url: "https://github.com/Iconica-Development/flutter_animated_widgets.git" + source: git + version: "0.0.1" flutter_lints: dependency: "direct dev" description: @@ -225,3 +234,4 @@ packages: version: "13.0.0" sdks: dart: ">=3.3.2 <4.0.0" + flutter: ">=1.17.0" diff --git a/lib/flutter_notification_center.dart b/lib/flutter_notification_center.dart index 2fe8aaf..1957def 100644 --- a/lib/flutter_notification_center.dart +++ b/lib/flutter_notification_center.dart @@ -8,3 +8,6 @@ export 'package:flutter_notification_center/src/services/notification_service.da export 'package:flutter_notification_center/src/notification_center.dart'; export 'package:flutter_notification_center/src/models/notification.dart'; export 'package:flutter_notification_center/src/models/notification_theme.dart'; +export 'package:flutter_notification_center/src/models/notification_config.dart'; +export 'package:flutter_notification_center/src/notification_bell.dart'; +export 'package:flutter_notification_center/src/notification_bell_story.dart'; diff --git a/lib/src/models/notification_config.dart b/lib/src/models/notification_config.dart new file mode 100644 index 0000000..d2b4d0d --- /dev/null +++ b/lib/src/models/notification_config.dart @@ -0,0 +1,14 @@ +import 'package:flutter_notification_center/flutter_notification_center.dart'; +import 'package:flutter_notification_center/src/models/notification_translation.dart'; + +class NotificationConfig { + final NotificationService service; + final NotificationStyle style; + final NotificationTranslations translations; + + const NotificationConfig({ + required this.service, + this.style = const NotificationStyle(), + this.translations = const NotificationTranslations(), + }); +} diff --git a/lib/src/notification_bell.dart b/lib/src/notification_bell.dart new file mode 100644 index 0000000..e17ad8b --- /dev/null +++ b/lib/src/notification_bell.dart @@ -0,0 +1,31 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_animated_widgets/flutter_animated_widgets.dart'; +import 'package:flutter_notification_center/flutter_notification_center.dart'; + +class NotificationBell extends StatefulWidget { + const NotificationBell({ + required this.config, + this.onTap, + super.key, + }); + + final NotificationConfig config; + final VoidCallback? onTap; + + @override + State createState() => _NotificationBellState(); +} + +class _NotificationBellState extends State { + @override + Widget build(BuildContext context) { + return IconButton( + onPressed: widget.onTap, + icon: AnimatedNotificationBell( + duration: const Duration(seconds: 1), + notificationCount: widget.config.service.listOfNotifications.length, + notificationIconSize: 45, + ), + ); + } +} diff --git a/lib/src/notification_bell_story.dart b/lib/src/notification_bell_story.dart new file mode 100644 index 0000000..13b08a7 --- /dev/null +++ b/lib/src/notification_bell_story.dart @@ -0,0 +1,27 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_notification_center/flutter_notification_center.dart'; + +class NotificationBellWidgetStory extends StatelessWidget { + const NotificationBellWidgetStory({ + required this.config, + super.key, + }); + + final NotificationConfig config; + + @override + Widget build(BuildContext context) { + return NotificationBell( + config: config, + onTap: () { + Navigator.of(context).push( + MaterialPageRoute( + builder: (context) => NotificationCenter( + config: config, + ), + ), + ); + }, + ); + } +} diff --git a/lib/src/notification_center.dart b/lib/src/notification_center.dart index 04c1a15..6019d20 100644 --- a/lib/src/notification_center.dart +++ b/lib/src/notification_center.dart @@ -1,20 +1,13 @@ import 'package:flutter/material.dart'; -import 'package:flutter_notification_center/src/models/notification.dart'; -import 'package:flutter_notification_center/src/models/notification_theme.dart'; -import 'package:flutter_notification_center/src/models/notification_translation.dart'; -import 'package:flutter_notification_center/src/services/notification_service.dart'; +import 'package:flutter_notification_center/flutter_notification_center.dart'; import 'package:intl/intl.dart'; class NotificationCenter extends StatefulWidget { - final NotificationService notificationCenterService; - final NotificationStyle? notificationTheme; - final NotificationTranslations translations; + final NotificationConfig config; const NotificationCenter({ super.key, - required this.notificationCenterService, - this.notificationTheme, - this.translations = const NotificationTranslations(), + required this.config, }); @override @@ -27,7 +20,7 @@ class _NotificationCenterState extends State { @override void initState() { super.initState(); - listOfNotifications = widget.notificationCenterService.getNotifications(); + listOfNotifications = widget.config.service.getNotifications(); } @override @@ -39,8 +32,8 @@ class _NotificationCenterState extends State { return Scaffold( appBar: AppBar( title: Text( - widget.translations.appBarTitle, - style: widget.notificationTheme?.appTitleTextStyle, + widget.config.translations.appBarTitle, + style: widget.config.style.appTitleTextStyle, ), centerTitle: true, leading: IconButton( @@ -51,9 +44,9 @@ class _NotificationCenterState extends State { ), ), body: unreadNotifications.isEmpty - ? widget.notificationTheme?.emptyNotificationsBuilder?.call() ?? + ? widget.config.style.emptyNotificationsBuilder?.call() ?? Center( - child: Text(widget.translations.appBarTitle), + child: Text(widget.config.translations.appBarTitle), ) : ListView.builder( itemCount: unreadNotifications.length, @@ -62,7 +55,7 @@ class _NotificationCenterState extends State { final formattedDateTime = DateFormat('yyyy-MM-dd HH:mm') .format(notification.dateTime); return Container( - decoration: widget.notificationTheme?.tileDecoration, + decoration: widget.config.style.tileDecoration, child: ListTile( title: Column( mainAxisSize: MainAxisSize.min, @@ -70,12 +63,12 @@ class _NotificationCenterState extends State { children: [ Text( notification.title, - style: widget.notificationTheme?.titleTextStyle ?? + style: widget.config.style.titleTextStyle ?? const TextStyle(), ), Text( notification.body, - style: widget.notificationTheme?.subtitleTextStyle ?? + style: widget.config.style.subtitleTextStyle ?? const TextStyle(), ), Text( diff --git a/pubspec.lock b/pubspec.lock index 7a012b5..e718625 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -62,6 +62,15 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_animated_widgets: + dependency: "direct main" + description: + path: "." + ref: "0.0.1" + resolved-ref: "0eb6ea4c2e64b757b468e23ee2055e27e8302397" + url: "https://github.com/Iconica-Development/flutter_animated_widgets.git" + source: git + version: "0.0.1" flutter_lints: dependency: "direct dev" description: @@ -218,3 +227,4 @@ packages: version: "13.0.0" sdks: dart: ">=3.3.2 <4.0.0" + flutter: ">=1.17.0" diff --git a/pubspec.yaml b/pubspec.yaml index dbc7965..047b6fd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -32,6 +32,10 @@ dependencies: sdk: flutter intl: ^0.17.0 + flutter_animated_widgets: + git: + url: https://github.com/Iconica-Development/flutter_animated_widgets.git + ref: 0.0.1 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons.