Why Do I Need To Cast The Value Of The Rx Object On Initialization?
Consider this code:
Rx<Widget> rxwidget = const Text("test").obs; rxwidget.value = Container();
This will throw the following error on runtime
Expected a value of type 'Text', but got one of type 'Container'
This seems very illogical to me because the variable only requires it to be a
Widget which both are. It somehow restricts the type to the first value it gets.
But if I write it like this:
Rx<Widget> rxwidget = (const Text("test") as Widget).obs; rxwidget.value = Container();
It works fine, but the IDE (Android Studio) actually complains that the cast is unnecessary.
Note, removing the
const keyword doesn't help.
Rx<String?> test = null.obs; test.value = "test";
Expected a value of type 'Null', but got one of type 'String'
I'm pretty sure it used to work, so I suspect it's a recent change in flutter.
Is this maybe an error in flutter/dart? Or why is this?
Flutter 2.10.3 • channel stable • https://github.com/flutter/flutter.git Framework • revision 7e9793dee1 (2 weeks ago) • 2022-03-02 11:23:12 -0600 Engine • revision bd539267b4 Tools • Dart 2.16.1 • DevTools 2.9.2
Rx<T> get obs => Rx<T>(this);
(const Text("test")).obs has type
Rx<Text> -> wrong
final rxwidget = Rx<Widget>(const Text("test"));
- → How do you create a 12 or 24 mnemonics code for multiple cryptocurrencies (ETH, BTC and so on..)
- → Flutter: input text field don't work properly in a simple example..... where am I wrong?
- → Can I customize the code formatting of Dart code in Atom?
- → Is it possible to develop iOS apps with Flutter on a Linux virtual machine?
- → Display SnackBar in Flutter
- → JSON ObjectMapper in Flutter
- → Material flutter app source code
- → TabBarSelection No such method error
- → How do I set the animation color of a LinearProgressIndicator?
- → Add different routes/screens to Flutter app
- → Is there a way to get the size of an existing widget?
- → How to share a file using flutter
- → Is there an easy way to find particular text built from RichText in a Flutter test?