flutterflutter-layoutstate-managementflutter-getxflutter-state

flutter getx, getview with two controllers


I'm a little bit confused with how GetView works. I currently have a page that needs to have at least 2 different controllers. From what I've seen, people mostly use GetView as opposed to Get.find() for better code format, however GetView seems to only use 1 controller, for example:

class HomeScreen extends GetView<HomeController>

I have tried to google it and haven't found any solution. I also have tried to use

class HomeScreen extends GetView<HomeController> with GetView<UserController>

But it gave me an error that says

The class 'GetView' can't be used as a mixin because it extends a class other than 'Object'.

I would very appreciate if you can give me a solution or a workaround to use GetView with two or more controllers.

Please note that I'm using GetX bindings (therefore I have already wrote Get.put(Controller()) in another file) and I want to avoid using Get.find in my widget tree.


Solution

  • Can you please explain what's the usecase of using GetView with multiple controllers? It's not supported. Because a view can have multiple controllers but how many?

    Therefore, in that case, you should just use the GetX widget for different controllers like:

    GetX<Controller1>(),
    GetX<Controller2>(),
    

    and so on