Initial project
This commit is contained in:
2
packages/notification_sdk/lib/notification_sdk.dart
Normal file
2
packages/notification_sdk/lib/notification_sdk.dart
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
export 'src/presentation/facade/notification_sdk_api.dart';
|
||||
@@ -0,0 +1,17 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'notification_sdk_platform_interface.dart';
|
||||
|
||||
/// An implementation of [NotificationSdkPlatform] that uses method channels.
|
||||
class MethodChannelNotificationSdk extends NotificationSdkPlatform {
|
||||
/// The method channel used to interact with the native platform.
|
||||
@visibleForTesting
|
||||
final methodChannel = const MethodChannel('notification_sdk');
|
||||
|
||||
@override
|
||||
Future<String?> getPlatformVersion() async {
|
||||
final version = await methodChannel.invokeMethod<String>('getPlatformVersion');
|
||||
return version;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
|
||||
|
||||
import 'notification_sdk_method_channel.dart';
|
||||
|
||||
abstract class NotificationSdkPlatform extends PlatformInterface {
|
||||
/// Constructs a NotificationSdkPlatform.
|
||||
NotificationSdkPlatform() : super(token: _token);
|
||||
|
||||
static final Object _token = Object();
|
||||
|
||||
static NotificationSdkPlatform _instance = MethodChannelNotificationSdk();
|
||||
|
||||
/// The default instance of [NotificationSdkPlatform] to use.
|
||||
///
|
||||
/// Defaults to [MethodChannelNotificationSdk].
|
||||
static NotificationSdkPlatform get instance => _instance;
|
||||
|
||||
/// Platform-specific implementations should set this with their own
|
||||
/// platform-specific class that extends [NotificationSdkPlatform] when
|
||||
/// they register themselves.
|
||||
static set instance(NotificationSdkPlatform instance) {
|
||||
PlatformInterface.verifyToken(instance, _token);
|
||||
_instance = instance;
|
||||
}
|
||||
|
||||
Future<String?> getPlatformVersion() {
|
||||
throw UnimplementedError('platformVersion() has not been implemented.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
|
||||
class NotificationSdkMethodChannel
|
||||
{
|
||||
// Channel Name
|
||||
static const String channelName = 'notification_sdk';
|
||||
|
||||
//---------------- Flutter call native ----------------
|
||||
|
||||
static const String requestPermission = 'requestPermission';
|
||||
|
||||
|
||||
//---------------- Flutter call native ----------------
|
||||
|
||||
|
||||
|
||||
//---------------- native call Flutter ----------------
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//---------------- native call Flutter ----------------
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import '../../../notification_sdk_platform_interface.dart';
|
||||
|
||||
class NotificationSdkMethodChannelDataSource
|
||||
{
|
||||
|
||||
final NotificationSdkPlatform platform;
|
||||
|
||||
NotificationSdkMethodChannelDataSource(this.platform);
|
||||
|
||||
|
||||
Future<String?> getPlatformVersion() async {
|
||||
return await getPlatformVersion();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
/// Data Transfer Object
|
||||
/// - 只負責資料傳輸 / 解析
|
||||
/// - 結構可變
|
||||
/// - 可以依賴 JSON / platform
|
||||
class NotificationSdkPermissionStatusDto {
|
||||
final bool granted;
|
||||
final bool permanentlyDenied;
|
||||
final String? grantedAt; // 通常是 raw string
|
||||
|
||||
NotificationSdkPermissionStatusDto({
|
||||
required this.granted,
|
||||
required this.permanentlyDenied,
|
||||
this.grantedAt,
|
||||
});
|
||||
|
||||
factory NotificationSdkPermissionStatusDto.fromJson(
|
||||
Map<String, dynamic> json,
|
||||
) {
|
||||
return NotificationSdkPermissionStatusDto(
|
||||
granted: json['granted'] as bool,
|
||||
permanentlyDenied: json['permanentlyDenied'] as bool,
|
||||
grantedAt: json['grantedAt'] as String?,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
//Repository Impl
|
||||
|
||||
import '../../domain/repositories/notification_sdk_repository.dart';
|
||||
import '../datasources/notification_sdk_method_channel_datasource.dart';
|
||||
|
||||
class NotificationSdkRepositoryImpl implements NotificationSdkRepository
|
||||
{
|
||||
final NotificationSdkMethodChannelDataSource _datasource;
|
||||
|
||||
const NotificationSdkRepositoryImpl(this._datasource);
|
||||
|
||||
@override
|
||||
Future<String?> platformVersion() {
|
||||
return _datasource.getPlatformVersion();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/// Domain Entity
|
||||
/// - 表達「通知權限狀態」這個業務概念
|
||||
/// - 穩定、可被 Facade 回傳
|
||||
/// - 不要包含 JSON / platform / plugin
|
||||
class NotificationSdkPermissionStatus {
|
||||
final bool isGranted;
|
||||
final bool isPermanentlyDenied;
|
||||
final DateTime? grantedAt;
|
||||
|
||||
const NotificationSdkPermissionStatus({
|
||||
required this.isGranted,
|
||||
required this.isPermanentlyDenied,
|
||||
this.grantedAt,
|
||||
});
|
||||
|
||||
/// 純業務邏輯允許
|
||||
bool get canRequestAgain => !isGranted && !isPermanentlyDenied;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// Repository Interface(Domain)
|
||||
|
||||
abstract class NotificationSdkRepository {
|
||||
Future<String?> platformVersion();
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
//UseCase
|
||||
|
||||
import '../repositories/notification_sdk_repository.dart';
|
||||
|
||||
class PlatformVersion
|
||||
{
|
||||
final NotificationSdkRepository _repository;
|
||||
|
||||
const PlatformVersion(this._repository);
|
||||
|
||||
Future<String?> call() {
|
||||
return _repository.platformVersion();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
|
||||
|
||||
import '../wiring/notification_sdk_wiring.dart';
|
||||
|
||||
/// SDK API
|
||||
abstract class NotificationSdkApi
|
||||
{
|
||||
factory NotificationSdkApi() => NotificationSdkWiring.build();
|
||||
|
||||
Future<String?> platformVersion();
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
|
||||
import '../../../notification_sdk.dart';
|
||||
import 'notification_sdk_core.dart';
|
||||
/// SDK API Implementation
|
||||
class NotificationSdkApiImpl implements NotificationSdkApi
|
||||
{
|
||||
final NotificationSdkCore _core;
|
||||
|
||||
NotificationSdkApiImpl({required NotificationSdkCore core}) : _core = core;
|
||||
|
||||
@override
|
||||
Future<String?> platformVersion() => _core.repo.platformVersion();
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
import '../../../notification_sdk_platform_interface.dart';
|
||||
import '../../domain/repositories/notification_sdk_repository.dart';
|
||||
|
||||
class NotificationSdkCore
|
||||
{
|
||||
final NotificationSdkPlatform platform;
|
||||
final NotificationSdkRepository repo;
|
||||
|
||||
NotificationSdkCore({
|
||||
required this.platform,
|
||||
required this.repo,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
|
||||
import '../../../notification_sdk.dart';
|
||||
|
||||
import '../../../notification_sdk_method_channel.dart';
|
||||
import '../../../notification_sdk_platform_interface.dart';
|
||||
|
||||
import '../../data/datasources/notification_sdk_method_channel_datasource.dart';
|
||||
import '../../data/repositories/notification_sdk_repository_impl.dart';
|
||||
|
||||
import 'notification_sdk_core.dart';
|
||||
import 'notification_sdk_api_impl.dart';
|
||||
|
||||
class NotificationSdkWiring
|
||||
{
|
||||
static NotificationSdkApi build() {
|
||||
|
||||
// platform instance(method channel)
|
||||
final platform = NotificationSdkPlatform.instance;
|
||||
if (platform is MethodChannelNotificationSdk) {
|
||||
// platform.init(); // or defer to NotificationApiImpl.init
|
||||
}
|
||||
|
||||
// data layer
|
||||
final ds = NotificationSdkMethodChannelDataSource(platform);
|
||||
final repo = NotificationSdkRepositoryImpl(ds);
|
||||
final core = NotificationSdkCore(platform: platform, repo: repo,);
|
||||
|
||||
return NotificationSdkApiImpl(core: core);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user