【问题标题】:How to conditional render GetxController如何有条件地渲染 GetxController
【发布时间】:2021-11-19 06:53:44
【问题描述】:

如果我想根据之前的路由名称获取GetxController,这个sn-p应该怎么编码?

  @override
  Widget build(BuildContext context) {
    MyGetxController? controller;
    if (Get.previousRoute != '/home') {
      controller = Get.find();
    }
    ...
  }

MyGetxController 已经放在了除主路由之外的其他路由中。

【问题讨论】:

    标签: flutter flutter-getx


    【解决方案1】:

    虽然不是最佳实践,但我将任何潜在的条件隔离在其隔离区中。

      @override
      Widget build(BuildContext context) {
        if (Get.previousRoute != '/home') {
          final MyGetxController? controller = Get.find();
          return ...
        } else {
          return ...
        }
      }
    

    【讨论】:

      猜你喜欢
      • 2011-05-21
      • 2018-06-30
      • 2014-11-26
      • 2012-11-20
      • 1970-01-01
      • 1970-01-01
      • 2019-03-24
      • 2013-05-01
      • 1970-01-01
      相关资源
      最近更新 更多