wyatt_cloud_messaging_bloc_base (0.1.1+2)

Published 2023-08-28 13:51:40 +00:00 by malo in Wyatt-FOSS/wyatt-packages

Installation

dart pub add wyatt_cloud_messaging_bloc_base:0.1.1+2 --hosted-url=

About this package

A starting point for Dart libraries or applications.

Cloud Messaging BLoC Base

Style: Wyatt Analysis SDK: Flutter

This package serves as an abstraction for managing notifications within Flutter applications. It does not include a built-in data source implementation. Therefore, it is essential to provide your own implementation or utilize one of our various implementations listed below:

This package enables you to easily integrate your data source, allowing the package to handle business logic, error management, and state logic seamlessly.

Features

  • 🧐 Wyatt Architecture
  • 🧱 Entities
    • RemoteNotification -> Contains notification innformations
  • 🧊 Cubits, why make it complicated when you can make it simple?
    • Goes to the essential
  • 📐 Consistent
    • Every class have same naming convention

Getting started

Simply add wyatt_cloud_messaging_bloc_base in pubspec.yaml , then

import 'package:wyatt_cloud_messaging_bloc_base/wyatt_cloud_messaging_bloc_base.dart';

Usage

Data source

The initial step involves furnishing a data source, presenting you with two options:

  • You can select from our provided implementations, which are listed above.
  • Alternatively, you can craft a custom implementation by extending the CloudMessagingRemoteDataSource class and implementing all of its methods.

In this example, we will use the Firebase Cloud Messaging implementation.

getIt.registerLazySingleton<CloudMessagingRemoteDataSource>(
    () => CloudMessagingFirebaseDataSource())

Here we use GetIt.

Repository

Do the same for the repository. This one is already developed, you just need to inject it.

getIt.registerLazySingleton<CloudMessagingRepository>(
    () => CloudMessagingRepositoryImpl(
        notificationRemoteDataSource: getIt(),
    ),
)

Use cases

Do the same for use cases. Select an inject the ones you need in your app. Here are avalaible use cases:

  • GetCloudMessagingTokenUsCase
  • InitCloudmessagingUseCase
  • ListenCloudMessagingUseCase
  • RequestCloudMessagingPermissionUseCase
  • SubscribeToNotificationTopicUseCase
  • UnsubscribeFromNotificationTopicUseCase

Here is an example with some usecase.

getIt
    ..registerLazySingleton<ListenNotificationUseCase>(
      () => ListenNotificationUseCase(
        notificationRepository: getIt(),
      ),
    )
    ..registerLazySingleton<GetCloudMessagingTokenUseCase>(
      () => GetCloudMessagingTokenUseCase(
        notificationRepository: getIt(),
      ),
    )
    ..registerLazySingleton<RequestCloudMessagingPermissionUseCase>(
      () => RequestCloudMessagingPermissionUseCase(
        notificationRepository: getIt(),
      ),
    );

Widgets

From this point onward, your task simply involves enveloping your app within the CloudMessagingWrapperScreen. Subsequently, you can proceed to implement your desired actions for handling incoming notifications.

Additional information

If necessary, you can access data sources, repositories, and use cases through getIt. Here's a helpful example:

abstract class CloudMessagingHelper {
  static Future<void> initMessaging() async {
    await getIt<RequestCloudMessagingPermissionUseCase>().call(null);

    final token = await getIt<GetCloudMessagingTokenUseCase>().call(null);
    if (token.isOk) {
      await notifLocalDataSource.storeToken(token: token.ok!);
    }
  }

  static dataProcess(String? path) {
    if (PageEnum.values.where((element) => (element.path == path)).isNotEmpty) {
      AppRouter.goRouterNavigatorKey.currentState?.context.push(path!);
    }
  }
}
Details
Pub
2023-08-28 13:51:40 +00:00
41
18 KiB
Assets (1)
Versions (4) View all
0.1.1+3 2023-11-18
0.1.1+2 2023-08-28
0.1.1+1 2023-08-18
0.1.1 2023-08-18