【问题标题】:how to update selected radio button in flutter using getx如何使用getx更新flutter中选定的单选按钮
【发布时间】:2021-05-25 07:34:52
【问题描述】:

我正在使用带有 GetX 插件的 Flutter,并且我在 statelesswidget 中有三个单选按钮,但是当用户单击它时单选按钮不会更改为选中,所以我的问题是如何使用 GetX 插件更新选定的单选按钮。这是我的代码

                  activeColor: mainColor1,
                  materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
                  // checkColor: Colors.white,
                  value: isSelected,
                  onChanged: (value) {
                    print('=====');
                    setState(() {
                      isSelected = value;
                      widget.onPress(value);
                    });
            })
          ), 

这是我的控制器端


  changeStatus(String select, bool condition) {

    if (condition) {
      selected.add(select);
    } else {
      selected.remove(select);
    }
    print(selected.length);
    update();
  }

【问题讨论】:

    标签: flutter controller radio-button state-management flutter-getx


    【解决方案1】:

    你必须像这样初始化你的控制器:

    final Controller _controller = Get.put(Controller());
    

    在onChanged 中这样调用你的方法:

    _controller.your method
    

    & 将整个下拉小部件放入:

    Obx(()=>DropdownButton)
    

    【讨论】:

      猜你喜欢
      • 2021-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多