onInit method
override
Called immediately after the widget is allocated in memory. You might use this to initialize something for the controller.
Implementation
@override
void onInit() async {
_devicesSubscription = MediaUtils.onDeviceChange.listen((e) {
devices.value = e.audio().toList();
selected.value = devices.firstWhereOrNull((e) => e.id() == _mic);
});
_worker = ever(_settingsRepository.mediaSettings, (e) {
if (e != null) {
_mic = e.audioDevice;
selected.value = devices.firstWhereOrNull((e) => e.id() == _mic);
}
});
try {
_permissionSubscription = await WebUtils.microphonePermission();
devices.value = await MediaUtils.enumerateDevices(
MediaDeviceKind.audioInput,
);
selected.value = devices.firstWhereOrNull((e) => e.id() == _mic);
} on UnsupportedError {
error.value = 'err_media_devices_are_null'.l10n;
} catch (e) {
if (e.toString().contains('Permission denied')) {
error.value = 'err_microphone_permission_denied'.l10n;
} else {
error.value = e.toString();
rethrow;
}
}
super.onInit();
}