|
|
@ -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 |
|
|
|