【问题标题】:Flutter number picker doesn't update on bottom sheet颤振数字选择器不会在底部工作表上更新
【发布时间】:2021-03-16 01:16:05
【问题描述】:

我想在底部工作表对话框中使用颤振数字选择器。但是号码选择器 当我通过滑动更改值时不会更新。我的代码如下。

GestureDetector(
                      onTap: (){
                        showModalBottomSheet<int>(
                            context: context,
                            builder: (BuildContext context){
                              return new Container(
                                height: 350.0,
                                color: HexColor('FF737373'),
                                child: new Container(
                                    decoration: new BoxDecoration(
                                        color: Colors.white,
                                        borderRadius: new BorderRadius.only(
                                            topLeft: const Radius.circular(20.0),
                                            topRight: const Radius.circular(20.0))),
                                    child: new Center(
                                      child: Column(
                                        mainAxisAlignment: MainAxisAlignment.center,
                                        children: <Widget>[
                                          NumberPicker.integer(
                                              initialValue: _currentValue,
                                              minValue: 0,
                                              maxValue: 1000,
                                          ),
                                        ],
                                      ),
                                    )),
                              );
                            }
                        ).then((int value) {
                          if (value != null) {
                            setState(() => _currentValue = value);
                          }
                        });
                      },

                      child: Container(
                        //container
                      ),
                    ),

【问题讨论】:

    标签: flutter numbers picker bottom


    【解决方案1】:

    我不明白你的目标是什么,但我希望这会有所帮助:

    showModalBottomSheet<int>(
      context: context,
      builder: (BuildContext context){
        return StatefulBuilder(
          builder: (BuildContext context, StateSetter setModalState) {
            return Container(
              height: 350.0,
              child: Container(
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.only(
                    topLeft: const Radius.circular(20.0),
                    topRight: const Radius.circular(20.0)
                  )
                ),
                child: Center(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      NumberPicker.integer(
                        initialValue: _currentValue,
                        minValue: 0,
                        maxValue: 1000,
                        onChanged: (value) {
                          setModalState(() {
                            _currentValue = value;
                          });
                        } 
                      ),
                    ],
                  ),
                )
              ),
            );
          }
        );
      }
    ).then((int value) {
      if(value != null) {
        setState(() => _currentValue = value);
      }
    });
    

    【讨论】:

      猜你喜欢
      • 2021-05-25
      • 2021-08-06
      • 1970-01-01
      • 1970-01-01
      • 2021-12-11
      • 1970-01-01
      • 1970-01-01
      • 2019-07-27
      • 2019-08-03
      相关资源
      最近更新 更多