-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to Watch Optional Property #8
Comments
can you paste the full stacktrace of when this happens? Might be a bug in watch_it |
Here is the stack trace:
It looks like the crash is on assert(observedProperty! is! Listenable, 'selectProperty returns a Listenable. Use watchIt instead'); Here is a simple project reproducing it: import 'package:flutter/material.dart';
import 'package:watch_it/watch_it.dart';
void main() {
di.registerSingleton<Test>(Test());
runApp(const MyApp());
}
class MyApp extends StatelessWidget with WatchItMixin {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
//~~~
watchPropertyValue((Test x) => x.selectedThing);
//~~~
return MaterialApp(
title: 'Watch It Test',
home: Column(
children: [
Text('Testing: ${Test.to.selectedThing}'),
TextButton(
onPressed: () {
final thing = Thing(name: 'hi');
Test.to.selectedThing = thing;
},
child: const Text('Set'),
),
],
),
);
}
}
class Test with ChangeNotifier {
static Test get to => di<Test>();
Thing? _selectedThing;
Thing? get selectedThing => _selectedThing;
set selectedThing(Thing? value) {
_selectedThing = value;
notifyListeners();
}
}
class Thing {
String name;
Thing({
required this.name,
});
} (As a side note, I use |
Fixed in V1.0.0 |
The fix works great! Thank you! 😄 |
You found an important bug that might have impacted others, so thanks for the report and analysis
Am 24. Aug. 2023, 19:47 +0200 schrieb Clifton Labrum ***@***.***>:
… The fix works great! Thank you! 😄
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you modified the open/close state.Message ID: ***@***.***>
|
I have an optional
selectedFlight
property in a class like this:...but it crashes when I set up the property value watcher in a widget:
How can I watch a nullable property that won't be set until later?
The text was updated successfully, but these errors were encountered: