|
|
@@ -0,0 +1,38 @@
|
|
|
+import 'package:flutter/services.dart';
|
|
|
+
|
|
|
+class NativeBridge {
|
|
|
+ static const MethodChannel _channel = MethodChannel('com.sinoMedCloud.bridge');
|
|
|
+
|
|
|
+ // 通用invoke
|
|
|
+ static Future<T?> invoke<T>(
|
|
|
+ String method, {
|
|
|
+ Map<String, dynamic>? params,
|
|
|
+ }) async {
|
|
|
+ try {
|
|
|
+ final result = await _channel.invokeMethod<T>(
|
|
|
+ method,
|
|
|
+ params
|
|
|
+ );
|
|
|
+ return result;
|
|
|
+ } on PlatformException catch (e) {
|
|
|
+ throw NativeBridgeException(
|
|
|
+ code: e.code,
|
|
|
+ message: e.message ?? 'Unknown error',
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+class NativeBridgeException implements Exception {
|
|
|
+ final String code;
|
|
|
+ final String message;
|
|
|
+
|
|
|
+ NativeBridgeException({
|
|
|
+ required this.code,
|
|
|
+ required this.message,
|
|
|
+ });
|
|
|
+
|
|
|
+ @override
|
|
|
+ String toString() => '[$code] $message';
|
|
|
+
|
|
|
+}
|