import 'dart:ui'; import 'package:aves/services/common/services.dart'; import 'package:flutter/services.dart'; abstract class DeviceService { Future> getCapabilities(); Future getDefaultTimeZone(); Future> getLocales(); Future getPerformanceClass(); Future isSystemFilePickerEnabled(); } class PlatformDeviceService implements DeviceService { static const platform = MethodChannel('deckers.thibault/aves/device'); @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 getDefaultTimeZone() async { try { return await platform.invokeMethod('getDefaultTimeZone'); } 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; } }