Skip to content

Commit

Permalink
Merge pull request #28 from Iconica-Development/5.0.0
Browse files Browse the repository at this point in the history
refactor: new component structure
  • Loading branch information
mighttymike authored Sep 24, 2024
2 parents ddf2a2b + 367303a commit 4065891
Show file tree
Hide file tree
Showing 51 changed files with 741 additions and 916 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ android/
web/
linux/
macos/
windows/

pubspec.lock
.metadata
flutter_notification_center.iml
dotenv
dotenv
firebase_options.dart
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [5.0.0] - 24 September 2024

* Refactor package with the new component structure

## [4.0.0] - 14 August 2024

* Fix overflow issue with long text in notification
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ A Flutter package for creating notification center displaying a list of notifica

To use this package, add `flutter_notification_center` as a dependency in your pubspec.yaml file.

- Provide a `NotificationService` to the userstory to define and alter behaviour, this service accepts and `NotificationRepositoryInterface` as repository (data source)

- For custom notification styling provide the optional notificationWidgetBuilder with your own implementation.

The `NotificationConfig` has its own parameters, as specified below:
| Parameter | Explanation |
|-----------|-------------|
| service | The notification service that will be used |
| seperateNotificationsWithDivider | If true notifications will be seperated with dividers within the notification center |
| translations | The translations that will be used |
| notificationWidgetBuilder | The widget that defines the styles and logic for every notification |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,8 @@ migrate_working_dir/
#.vscode/

# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.pub-cache/
.pub/
/build/
.dart_tools/

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release

# iOS related
/ios/

lib/config/
pubspec.lock
dotenv

build/
1 change: 1 addition & 0 deletions packages/firebase_notification_center_repository/LICENSE
1 change: 1 addition & 0 deletions packages/firebase_notification_center_repository/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ analyzer:
exclude:

linter:
rules:
rules:
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export "src/firebase_notification_repository.dart";
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
import "package:cloud_firestore/cloud_firestore.dart";
import "package:firebase_core/firebase_core.dart";
import "package:notification_center_repository_interface/notification_center_repository_interface.dart";

class FirebaseNotificationRepository
implements NotificationRepositoryInterface {
FirebaseNotificationRepository({
FirebaseApp? firebaseApp,
this.activeNotificationsCollection = "active_notifications",
this.plannedNotificationsCollection = "planned_notifications",
}) : firebaseApp = firebaseApp ?? Firebase.app();

final FirebaseApp firebaseApp;
final String activeNotificationsCollection;
final String plannedNotificationsCollection;

@override
Future<NotificationModel> addNotification(
String userId,
NotificationModel notification,
List<String> recipientIds,
) async {
var newNotification = notification;

for (var recipientId in recipientIds) {
DocumentReference notifications;
if (notification.scheduledFor != null &&
notification.scheduledFor!.isAfter(DateTime.now())) {
notifications = FirebaseFirestore.instanceFor(app: firebaseApp)
.collection(plannedNotificationsCollection)
.doc(recipientId)
.collection(plannedNotificationsCollection)
.doc(notification.id);
} else {
newNotification = notification.copyWith(
id: "${notification.id}-${DateTime.now().millisecondsSinceEpoch}",
);

notifications = FirebaseFirestore.instanceFor(app: firebaseApp)
.collection(activeNotificationsCollection)
.doc(recipientId)
.collection(activeNotificationsCollection)
.doc(newNotification.id);
}

var currentDateTime = DateTime.now();
newNotification.dateTimePushed = currentDateTime;
var notificationMap = newNotification.toMap();
await notifications.set(notificationMap);
}

return newNotification;
}

@override
Future<void> deleteNotification(
String userId,
String id,
bool planned,
) async {
try {
if (planned) {
await FirebaseFirestore.instanceFor(app: firebaseApp)
.collection(plannedNotificationsCollection)
.doc(userId)
.collection(plannedNotificationsCollection)
.doc(id)
.delete();
} else {
await FirebaseFirestore.instanceFor(app: firebaseApp)
.collection(activeNotificationsCollection)
.doc(userId)
.collection(activeNotificationsCollection)
.doc(id)
.delete();
}
} catch (e) {
throw Exception("Failed to delete notification: $e");
}
}

@override
Stream<NotificationModel?> getNotification(String userId, String id) {
var notificationStream = FirebaseFirestore.instanceFor(app: firebaseApp)
.collection(activeNotificationsCollection)
.doc(userId)
.collection(activeNotificationsCollection)
.doc(id)
.snapshots()
.map((snapshot) {
if (snapshot.exists) {
if (snapshot.data() == null) {
return null;
}

return NotificationModel.fromJson(snapshot.data()!);
} else {
return null;
}
});

return notificationStream;
}

@override
Stream<List<NotificationModel>> getNotifications(String userId) {
var notificationsStream = FirebaseFirestore.instanceFor(app: firebaseApp)
.collection(activeNotificationsCollection)
.doc(userId)
.collection(activeNotificationsCollection)
.snapshots()
.map(
(snapshot) => snapshot.docs
.map((doc) => NotificationModel.fromJson(doc.data()))
.toList(),
);

return notificationsStream;
}

@override
Future<NotificationModel> updateNotification(
String userId,
NotificationModel notification,
) async {
await FirebaseFirestore.instanceFor(app: firebaseApp)
.collection(activeNotificationsCollection)
.doc(userId)
.collection(activeNotificationsCollection)
.doc(notification.id)
.update(notification.toMap());

return notification;
}

@override
Stream<List<NotificationModel>> getPlannedNotifications(String userId) {
var notificationsStream = FirebaseFirestore.instanceFor(app: firebaseApp)
.collection(plannedNotificationsCollection)
.doc(userId)
.collection(plannedNotificationsCollection)
.snapshots()
.map(
(snapshot) => snapshot.docs
.map((doc) => NotificationModel.fromJson(doc.data()))
.toList(),
);

return notificationsStream;
}
}
31 changes: 31 additions & 0 deletions packages/firebase_notification_center_repository/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: firebase_notification_center_repository
description: "A new Flutter package project."
version: 5.0.0
homepage:
publish_to: 'none'

environment:
sdk: ^3.5.3
flutter: ">=1.17.0"

dependencies:
flutter:
sdk: flutter

# Firebase
cloud_firestore: ^5.4.2
firebase_core: ^3.5.0

notification_center_repository_interface:
git:
url: https://github.com/Iconica-Development/flutter_notification_center.git
path: packages/notification_center_repository_interface
ref: 5.0.0

dev_dependencies:
flutter_iconica_analysis:
git:
url: https://github.com/Iconica-Development/flutter_iconica_analysis
ref: 7.0.0

flutter:
20 changes: 3 additions & 17 deletions packages/flutter_notification_center/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,8 @@ migrate_working_dir/
#.vscode/

# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.pub-cache/
.pub/
/build/

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release
build/
1 change: 1 addition & 0 deletions packages/flutter_notification_center/CHANGELOG.md
1 change: 1 addition & 0 deletions packages/flutter_notification_center/LICENSE
1 change: 1 addition & 0 deletions packages/flutter_notification_center/README.md
2 changes: 1 addition & 1 deletion packages/flutter_notification_center/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ analyzer:
exclude:

linter:
rules:
rules:
9 changes: 0 additions & 9 deletions packages/flutter_notification_center/example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ migrate_working_dir/
.pub-cache/
.pub/
/build/
.dart_tools/

# Symbolication related
app.*.symbols
Expand All @@ -42,11 +41,3 @@ app.*.map.json
/android/app/debug
/android/app/profile
/android/app/release

# iOS related
/ios/

lib/config/
pubspec.lock
dotenv
firebase_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ linter:
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
1 change: 1 addition & 0 deletions packages/flutter_notification_center/example/firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"flutter":{"platforms":{"dart":{"lib/firebase_options.dart":{"projectId":"appshell-demo","configurations":{"web":"1:431820621472:web:f4b27eea24be24fd1babc5"}}}}}}
Loading

0 comments on commit 4065891

Please sign in to comment.