Initial project
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
|
||||
class {{sdk_class}}MethodChannel
|
||||
{
|
||||
// Channel Name
|
||||
static const String channelName = '{{name}}';
|
||||
|
||||
//---------------- Flutter call native ----------------
|
||||
|
||||
static const String requestPermission = 'requestPermission';
|
||||
|
||||
|
||||
//---------------- Flutter call native ----------------
|
||||
|
||||
|
||||
|
||||
//---------------- native call Flutter ----------------
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//---------------- native call Flutter ----------------
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import 'package:flutter/services.dart';
|
||||
import '../../../{{name}}_platform_interface.dart';
|
||||
|
||||
class {{sdk_class}}MethodChannelDataSource
|
||||
{
|
||||
|
||||
final {{sdk_class}}Platform platform;
|
||||
|
||||
{{sdk_class}}MethodChannelDataSource(this.platform);
|
||||
|
||||
|
||||
Future<String?> getPlatformVersion() async {
|
||||
return await getPlatformVersion();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
/// Data Transfer Object
|
||||
/// - 只負責資料傳輸 / 解析
|
||||
/// - 結構可變
|
||||
/// - 可以依賴 JSON / platform
|
||||
class {{sdk_class}}PermissionStatusDto {
|
||||
final bool granted;
|
||||
final bool permanentlyDenied;
|
||||
final String? grantedAt; // 通常是 raw string
|
||||
|
||||
{{sdk_class}}PermissionStatusDto({
|
||||
required this.granted,
|
||||
required this.permanentlyDenied,
|
||||
this.grantedAt,
|
||||
});
|
||||
|
||||
factory {{sdk_class}}PermissionStatusDto.fromJson(
|
||||
Map<String, dynamic> json,
|
||||
) {
|
||||
return {{sdk_class}}PermissionStatusDto(
|
||||
granted: json['granted'] as bool,
|
||||
permanentlyDenied: json['permanentlyDenied'] as bool,
|
||||
grantedAt: json['grantedAt'] as String?,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
//Repository Impl
|
||||
|
||||
import '../../domain/repositories/{{name}}_repository.dart';
|
||||
import '../datasources/{{name}}_method_channel_datasource.dart';
|
||||
|
||||
class {{sdk_class}}RepositoryImpl implements {{sdk_class}}Repository
|
||||
{
|
||||
final {{sdk_class}}MethodChannelDataSource _datasource;
|
||||
|
||||
const {{sdk_class}}RepositoryImpl(this._datasource);
|
||||
|
||||
@override
|
||||
Future<String?> platformVersion() {
|
||||
return _datasource.getPlatformVersion();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/// Domain Entity
|
||||
/// - 表達「通知權限狀態」這個業務概念
|
||||
/// - 穩定、可被 Facade 回傳
|
||||
/// - 不要包含 JSON / platform / plugin
|
||||
class {{sdk_class}}PermissionStatus {
|
||||
final bool isGranted;
|
||||
final bool isPermanentlyDenied;
|
||||
final DateTime? grantedAt;
|
||||
|
||||
const {{sdk_class}}PermissionStatus({
|
||||
required this.isGranted,
|
||||
required this.isPermanentlyDenied,
|
||||
this.grantedAt,
|
||||
});
|
||||
|
||||
/// 純業務邏輯允許
|
||||
bool get canRequestAgain => !isGranted && !isPermanentlyDenied;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// Repository Interface(Domain)
|
||||
|
||||
abstract class {{sdk_class}}Repository {
|
||||
Future<String?> platformVersion();
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
//UseCase
|
||||
|
||||
import '../repositories/{{name}}_repository.dart';
|
||||
|
||||
class PlatformVersion
|
||||
{
|
||||
final {{sdk_class}}Repository _repository;
|
||||
|
||||
const PlatformVersion(this._repository);
|
||||
|
||||
Future<String?> call() {
|
||||
return _repository.platformVersion();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
|
||||
|
||||
import '../wiring/{{name}}_wiring.dart';
|
||||
|
||||
/// SDK API
|
||||
abstract class {{sdk_class}}Api
|
||||
{
|
||||
factory {{sdk_class}}Api() => {{sdk_class}}Wiring.build();
|
||||
|
||||
Future<String?> platformVersion();
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
|
||||
import '../../../{{name}}.dart';
|
||||
import '{{name}}_core.dart';
|
||||
/// SDK API Implementation
|
||||
class {{sdk_class}}ApiImpl implements {{sdk_class}}Api
|
||||
{
|
||||
{{sdk_class}}Core _core;
|
||||
|
||||
{{sdk_class}}ApiImpl({required {{sdk_class}}Core core}) : _core = core;
|
||||
|
||||
@override
|
||||
Future<String?> platformVersion() => _core.repo.platformVersion();
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
import '../../../{{name}}_platform_interface.dart';
|
||||
import '../../domain/repositories/{{name}}_repository.dart';
|
||||
|
||||
class {{sdk_class}}Core
|
||||
{
|
||||
final {{sdk_class}}Platform platform;
|
||||
final {{sdk_class}}Repository repo;
|
||||
|
||||
{{sdk_class}}Core({
|
||||
required this.platform,
|
||||
required this.repo,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
|
||||
import '../../../{{name}}.dart';
|
||||
|
||||
import '../../../{{name}}_method_channel.dart';
|
||||
import '../../../{{name}}_platform_interface.dart';
|
||||
|
||||
import '../../data/datasources/{{name}}_method_channel_datasource.dart';
|
||||
import '../../data/repositories/{{name}}_repository_impl.dart';
|
||||
|
||||
import '{{name}}_core.dart';
|
||||
import '{{name}}_api_impl.dart';
|
||||
|
||||
class {{sdk_class}}Wiring
|
||||
{
|
||||
static {{sdk_class}}Api build() {
|
||||
|
||||
// platform instance(method channel)
|
||||
final platform = {{sdk_class}}Platform.instance;
|
||||
if (platform is MethodChannel{{sdk_class}}) {
|
||||
// platform.init(); // or defer to NotificationApiImpl.init
|
||||
}
|
||||
|
||||
// data layer
|
||||
final ds = {{sdk_class}}MethodChannelDataSource(platform);
|
||||
final repo = {{sdk_class}}RepositoryImpl(ds);
|
||||
final core = {{sdk_class}}Core(platform: platform, repo: repo,);
|
||||
|
||||
return {{sdk_class}}ApiImpl(core: core);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
library {{name}};
|
||||
|
||||
export 'src/presentation/facade/{{name}}_api.dart';
|
||||
11
mason/bricks/clean_plugin_sdk/brick.yaml
Normal file
11
mason/bricks/clean_plugin_sdk/brick.yaml
Normal file
@@ -0,0 +1,11 @@
|
||||
name: clean_plugin_sdk
|
||||
description: Clean Architecture structure inside a Flutter plugin SDK
|
||||
version: 0.1.0
|
||||
vars:
|
||||
name:
|
||||
type: string
|
||||
description: sdk package name
|
||||
|
||||
sdk_class:
|
||||
type: string
|
||||
description: sdk class name (PascalCase)
|
||||
Reference in New Issue
Block a user