watchValue on a get property
matthewkooshad opened this issue · 6 comments
i have a class with ValueNotifier<bool> get valueNotifierFromToBeDeterminedClass
.
since it's a situation where the class is to be determined, in my watchValue, i can't hardcode that class name in watchValue.
how can i do this? thanks
ok, i've tried getting that syntax simply as you've stated, but unable so far. as i've exhausted the readme on the 5 examples of the basic watch function, i'll search around.
i think because my class is not extending Listenable interface and simply has a ValueNotifier property i'm trying to utilize as described.
even if i adjust the interface that the classes extend abstract class ITest<T> extends ChangeNotifier
, this wouldn't work for my situation, as i can't code to the interface in the watch, but need to code to the decision logic function in the watch... which i don't see how to achieve.
thanks,
class _Test extends WatchingWidget {
const _Test();
@override
Widget build(BuildContext context) {
final isEditing = watch(TestHelper).isEditing; // wrong
return Text(isEditing);
}
}
class TestHelper{
static ValueNotifier<bool> get isEditing {
return determineClassToUse().isEditing;
}
}
do it like this
class _Test extends WatchingWidget {
const _Test();
@override
Widget build(BuildContext context) {
final isEditing = watch(TestHelper.isEditing).value;
return Text(isEditing);
}
}
class TestHelper{
static ValueNotifier<bool> get isEditing {
return determineClassToUse().isEditing;
}
}
ah, i was close, thanks for the correction/help!
instead of:
final isEditing = watch(TestHelper).isEditing; // wrong
this works:
final isEditing = watch(TestHelper.isEditing).value;
thanks again