import 'dart:async'; import 'package:aves/services/common/services.dart'; import 'package:flutter/services.dart'; abstract class AppProfileService { Future canInteractAcrossProfiles(); Future canRequestInteractAcrossProfiles(); Future requestInteractAcrossProfiles(); Future getProfileSwitchingLabel(); Future switchProfile(); Future> getTargetUserProfiles(); } class PlatformAppProfileService implements AppProfileService { static const _platform = MethodChannel('deckers.thibault/aves/app_profile'); @override Future canInteractAcrossProfiles() async { try { final result = await _platform.invokeMethod('canInteractAcrossProfiles'); if (result != null) return result as bool; } on PlatformException catch (e, stack) { await reportService.recordError(e, stack); } return false; } @override Future canRequestInteractAcrossProfiles() async { try { final result = await _platform.invokeMethod('canRequestInteractAcrossProfiles'); if (result != null) return result as bool; } on PlatformException catch (e, stack) { await reportService.recordError(e, stack); } return false; } @override Future requestInteractAcrossProfiles() async { try { final result = await _platform.invokeMethod('requestInteractAcrossProfiles'); if (result != null) return result as bool; } on PlatformException catch (e, stack) { await reportService.recordError(e, stack); } return false; } @override Future switchProfile() async { try { await _platform.invokeMethod('switchProfile'); } on PlatformException catch (e, stack) { await reportService.recordError(e, stack); } return; } @override Future getProfileSwitchingLabel() async { try { final result = await _platform.invokeMethod('getProfileSwitchingLabel'); return result as String; } on PlatformException catch (e, stack) { await reportService.recordError(e, stack); } return ''; } @override Future> getTargetUserProfiles() async { try { final result = await _platform.invokeMethod('getTargetUserProfiles'); if (result != null) { return (result as List).cast(); } } on PlatformException catch (e, stack) { await reportService.recordError(e, stack); } return []; } }