| 1234567891011121314151617181920212223242526272829303132333435363738 |
- 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';
- }
|