flutter getx,带有两个控制器的 getview
我对 GetView 的工作原理有点困惑。我目前有一个页面需要至少有 2 个不同的控制器。据我所知,人们大多使用 GetView 而不是 Get.find() 来获得更好的代码格式,但是 GetView 似乎只使用 1 个控制器,例如:
class HomeScreen extends GetView
我尝试用谷歌搜索它,但没有找到任何解决方案。我还尝试使用
class HomeScreen extends GetView
但它给了我一个错误,说
“GetView”类不能用作 mixin,因为它扩展了“Object”以外的类。
如果您能给我一个解决方案或解决方法,以便将 GetView 与两个或多个控制器一起使用,我将非常感激。
请注意,我正在使用 GetX 绑定(因此我已经在另一个文件中编写了 Get.put(Controller())
)和 < strong>我想避免在我的小部件树中使用 Get.find。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您能否解释一下将 GetView 与多个控制器一起使用的用例是什么?不支持。因为一个视图可以有多个控制器,但是有多少个呢?
因此,在这种情况下,您应该只对不同的控制器使用 GetX 小部件,例如:
等等
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:
and so on
如果您需要在页面上使用多个控制器,只需使用 StatelessWidget,如下所示:
当您使用 getter 获取控制器时,您可以将您的小部件保留为 const。
避免
Get.find
似乎不是一个有效的要求If you need multiple controllers on the page just use StatelessWidget like this:
When you obtain your controllers using getter you can preserve your widget being
const
.Avoiding
Get.find
does not seem like a valid requirement