Commit 62536c66070595227ca6b8e5eee6acb6b9b8d3b0

Authored by 权海
1 parent 33a7b6b5

feat(ui):增加原生检测flutter引擎是否存活

... ... @@ -12,6 +12,7 @@ import '../../data/local/local_storage.dart';
import '../../data/local/user_account_storage.dart';
import '../../data/local/user_preferences_storage.dart';
import '../../core/services/loading_service.dart';
import '../../core/services/native_health_data_update_bridge.dart';
import '../bindings/initial_binding.dart';
/// Application startup before [runApp].
... ... @@ -41,6 +42,7 @@ abstract final class AppBootstrap {
).dependencies();
await userPreferencesStorage.syncLoginInfoToNative();
NativeHealthDataUpdateBridge.initialize();
LoadingService.init();
... ...
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'raw_data_service/health_raw_data_core_service.dart';
/// Receives native HealthKit work independently of the visible Flutter route.
abstract final class NativeHealthDataUpdateBridge {
static const _channel =
MethodChannel('doublefeel_flutter_health_update_channel');
static var _initialized = false;
static void initialize() {
if (_initialized) return;
_initialized = true;
_channel.setMethodCallHandler(_handleMethodCall);
}
static Future<Object?> _handleMethodCall(MethodCall call) async {
if (call.method == 'healthDataEngineReady') return true;
if (call.method != 'healthDataUpdated') return null;
final dataTypes = _dataTypes(call.arguments);
debugPrint('[NativeHealthDataUpdateBridge] calculate dataTypes=$dataTypes');
await Get.find<HealthRawDataCoreService>().onHealthDataUpdated(
dataTypes: dataTypes,
);
return true;
}
static List<int> _dataTypes(Object? arguments) {
final value = switch (arguments) {
{'dataTypes': final Object? dataTypes} => dataTypes,
{'data_types': final Object? dataTypes} => dataTypes,
_ => arguments,
};
if (value is! Iterable) return const <int>[];
return value.whereType<num>().map((value) => value.toInt()).toList();
}
}
... ...