简体   繁体   English

在使用 GetX 的 flutter 项目中,哪个导航代码是小部件或 controller 更好?

[英]In a flutter project that uses GetX, which navigation code is better a widget or a controller?

I'm making a flutter app using GetX.我正在使用 GetX 制作一个 flutter 应用程序。

I want to know where to write the navigation function of GetX, between widgets and controllers.我想知道在哪里写 GetX 的导航 function,在小部件和控制器之间。

ex) GetX.toNamed() , GetX.back()例如) GetX.toNamed() , GetX.back()

If the widget has to handle it, how do you deliver an event from the controller to the widget when the screen needs to be moved after.networking in the controller?如果小部件必须处理它,当屏幕需要在 controller 中移动时,您如何将事件从 controller 传递给小部件?

its simple.这很简单。

create another controller创建另一个 controller

and check your condition then然后检查你的情况

if true GetX.back() else return null如果为真GetX.back()否则返回null

Example.例子。

WillPopScope(
    onWillPop: () async {
      bool res = await controller.checkfun() ?? false;
      if (res) {
        return true;
      }
      return false;
    },
    child: ...
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM