From f7579f993d4c62f4255678b63cf4ffb0e8e3cbd1 Mon Sep 17 00:00:00 2001 From: Kate Doeen Date: Wed, 13 Jul 2022 21:52:03 +0200 Subject: [PATCH] settings: Throw error when accessing value of disabled option --- packages/settings/lib/src/options/option.dart | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/settings/lib/src/options/option.dart b/packages/settings/lib/src/options/option.dart index 6534d11e..7d529769 100644 --- a/packages/settings/lib/src/options/option.dart +++ b/packages/settings/lib/src/options/option.dart @@ -1,5 +1,7 @@ part of '../../settings.dart'; +class OptionDisableException implements Exception {} + abstract class Option { Option({ required this.storage, @@ -24,7 +26,13 @@ abstract class Option { late final BehaviorSubject enabled; late BehaviorSubject stream; - T get value => stream.value ?? defaultValue.value; + T get value { + if (!enabled.value) { + throw OptionDisableException(); + } + + return stream.value ?? defaultValue.value; + } void dispose() { // ignore: discarded_futures