【问题标题】:Can I access Flutter GetXController properties with variable name?我可以使用变量名访问 Flutter GetXController 属性吗?
【发布时间】:2022-01-18 07:07:22
【问题描述】:

希望你今天过得愉快。

我想知道我可以使用变量访问 GetXcontroller 属性

例如:

my_controller.dart

class MyController extends GexController {
  var isDocumentX = false.obs 
}

ui_page.dart

final myContr = Get.put(MyController());

// I want to access like this

myContr.{dynamic}.value

dynamic的值来自api,与本例中controller属性的值相同的是isDocumentX。

我希望我的问题和例子足够清楚,可以理解

谢谢

【问题讨论】:

    标签: android ios flutter dart


    【解决方案1】:

    我认为动态访问无法使用变量,但您应该尝试使用 Map

      Map<String, dynamic> myDocuments = <String, dynamic>{
        isDocumentX : false,
      }.obs;
    

    然后像下面这样访问

    myContr.{myDocuments[<dynamic_api_key>]}.value
    

    【讨论】:

      猜你喜欢
      • 2021-07-17
      • 2018-09-26
      • 1970-01-01
      • 2017-11-11
      • 2011-01-02
      • 2012-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多