Closed matthewkooshad closed 5 months ago
Just use the basic watch function and add a .value Am 15. Jan. 2024, 00:37 +0100 schrieb Matthew Kooshad @.***>:
i have a class with ValueNotifier
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 — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>
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.
Can you add a code snippet where you want to use it then I can show you Am 15. Jan. 2024, 17:21 +0100 schrieb Matthew Kooshad @.***>:
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. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>
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
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