load method
Implementation
@override
Future<Avatar>load({required String id, void Function(double progress)? onProgress}) async {
final eventID = '${id}_${DateTime.now().millisecondsSinceEpoch}';
StreamSubscription? subscription;
if (onProgress != null) {
subscription = _eventChannel.receiveBroadcastStream(eventID).listen((progress) {
onProgress(progress as double);
});
}
try {
final result = await _methodChannel.invokeMethod('load', {'id': id, 'eventID': eventID});
return Avatar.fromJson(Map<String, dynamic>.from(result));
} on PlatformException catch (e) {
final error = AvatarError.fromNameOrNull(e.code);
if (error != null) {
throw error;
} else {
rethrow;
}
} finally {
try {
await subscription?.cancel();
} catch (_) {
// ignore cancel errors
}
}
}