import 'dart:ui'; import 'package:aves/services/common/services.dart'; import 'package:flutter/services.dart'; abstract class DeviceService { Future canManageMedia(); Future> getCapabilities(); Future getDefaultTimeZoneRawOffsetMillis(); Future> getLocales(); Future getPerformanceClass(); Future isSystemFilePickerEnabled(); Future requestMediaManagePermission(); Future getAvailableHeapSize(); Future requestGarbageCollection(); } class PlatformDeviceService implements DeviceService { static const _platform = MethodChannel('deckers.thibault/aves/device'); @override Future canManageMedia() async { try { final result = await _platform.invokeMethod('canManageMedia'); if (result != null) return result as bool; } on PlatformException catch (e, stack) { await reportService.recordError(e, stack); } return false; } @override Future> getCapabilities() async { try { final result = await _platform.invokeMethod('getCapabilities'); if (result != null) return (result as Map).cast(); } on PlatformException catch (e, stack) { await reportService.recordError(e, stack); } return {}; } @override Future getDefaultTimeZoneRawOffsetMillis() async { try { return await _platform.invokeMethod('getDefaultTimeZoneRawOffsetMillis'); } on PlatformException catch (e, stack) { await reportService.recordError(e, stack); } return null; } @override Future> getLocales() async { try { final result = await _platform.invokeMethod('getLocales'); if (result != null) { return (result as List).cast().map((tags) { final language = tags['language'] as String?; final country = tags['country'] as String?; return Locale( language ?? 'und', (country != null && country.isEmpty) ? null : country, ); }).toList(); } } on PlatformException catch (e, stack) { await reportService.recordError(e, stack); } return []; } @override Future getPerformanceClass() async { try { final result = await _platform.invokeMethod('getPerformanceClass'); if (result != null) return result as int; } on PlatformException catch (e, stack) { await reportService.recordError(e, stack); } return 0; } @override Future isSystemFilePickerEnabled() async { try { final result = await _platform.invokeMethod('isSystemFilePickerEnabled'); if (result != null) return result as bool; } on PlatformException catch (e, stack) { await reportService.recordError(e, stack); } return false; } @override Future requestMediaManagePermission() async { try { await _platform.invokeMethod('requestMediaManagePermission'); } on PlatformException catch (e, stack) { await reportService.recordError(e, stack); } } @override Future getAvailableHeapSize() async { try { final result = await _platform.invokeMethod('getAvailableHeapSize'); if (result != null) return result as int; } on PlatformException catch (e, stack) { await reportService.recordError(e, stack); } return 0; } @override Future requestGarbageCollection() async { try { await _platform.invokeMethod('requestGarbageCollection'); } on PlatformException catch (e, stack) { await reportService.recordError(e, stack); } } }