Browse Source

settings: Throw error when accessing value of disabled option

pull/19/head
Kate Doeen 2 years ago
parent
commit
f7579f993d
No known key found for this signature in database
GPG Key ID: 9F81F962D88883F8
  1. 10
      packages/settings/lib/src/options/option.dart

10
packages/settings/lib/src/options/option.dart

@ -1,5 +1,7 @@
part of '../../settings.dart'; part of '../../settings.dart';
class OptionDisableException implements Exception {}
abstract class Option<T> { abstract class Option<T> {
Option({ Option({
required this.storage, required this.storage,
@ -24,7 +26,13 @@ abstract class Option<T> {
late final BehaviorSubject<bool> enabled; late final BehaviorSubject<bool> enabled;
late BehaviorSubject<T> stream; late BehaviorSubject<T> stream;
T get value => stream.value ?? defaultValue.value; T get value {
if (!enabled.value) {
throw OptionDisableException();
}
return stream.value ?? defaultValue.value;
}
void dispose() { void dispose() {
// ignore: discarded_futures // ignore: discarded_futures

Loading…
Cancel
Save