Seemingly unexpected behaviour of Obx. Could anyone please explain? #2958
Unanswered
tantalising
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying to wrap obx widget in a class to get a different syntax (for aesthetics reason). This is the below code:
`class Observable extends StatelessWidget {
final Widget child;
const Observable({super.key, required this.child});
@OverRide
Widget build(BuildContext context) {
return Obx(() => child);
}
}`
The aim of the class Observable is to change the syntax of making a widget observable. like this:
child: Center( child: Observable( child: Text( "${SecondCounterModel.to.count}", style: TextStyle( fontSize: Get.textTheme.headlineLarge?.fontSize), ), ), ),
The reason is to have a widget tree where the syntax is uniform. That is the child argument. Almost always in flutter a widget takes a argument named child (or children). This is of course not really important and it is purely for aesthetic reason.
Now the problem is this doesn't work. The getx complains that either the widget doesn't have a reactive variable inside or the context is not suitable for update. The former case is not true obviously.
I would like to know if it is possible to get around this.
Beta Was this translation helpful? Give feedback.
All reactions