If I have a local ValueNotifier and attempt to use registerHandler, I get an error:
Invalid argument(s): Either the return type of the select function or the type T has to be a Listenable
This tracks down to the following check in registerHandler:
if (T is Listenable) {
observedObject = (parentObject) as Listenable;
} else {
throw ArgumentError(
'Either the return type of the select function or the type T has to be a Listenable');
}
I'm using it like this:
class MyWidget extends WatchingStatefulWidget {
...
}
class _MyWidgetState extends State<MyWidget> {
final ValueNotifier<int> _myValueNotifier = ValueNotifier(0);
@override
Widget build(BuildContext context) {
registerHandler(
target: _myValueNotifier,
handler: (context, value, cancel) {
print('value is $value');
}
);
...
}
}
But this is probably the wrong thing to check. In this case,
print(ValueNotifier is Listenable); // prints false
print(_myValueNotifier is Listenable); // prints true
I have no earthly idea why ValueNotifier is Listenable evaluates to false, but it certainly does.
If I have a local
ValueNotifier
and attempt to useregisterHandler
, I get an error:This tracks down to the following check in
registerHandler
:I'm using it like this:
But this is probably the wrong thing to check. In this case,
I have no earthly idea why
ValueNotifier is Listenable
evaluates to false, but it certainly does.