【问题标题】:Flutter Duration User Input颤振持续时间用户输入
【发布时间】:2020-01-28 10:07:30
【问题描述】:

在我的应用中,我需要用户给我一个持续时间,我正在考虑秒和分钟。因此,在按下按钮后,我想要一个弹出窗口之类的东西,然后用户可以通过滚动列表并选择分钟和秒(或类似的东西)来选择持续时间。

经过长时间的互联网搜索,我找不到任何类似的模板,我真的不想手动编写所有代码。我会很感激一个模板的链接,如果不是的话,可能会建议什么是正确的方法来做这样的事情。

【问题讨论】:

    标签: user-interface flutter user-input


    【解决方案1】:

    您可以为此使用flutter_picker 包。

    以下 sn-p 显示了一个需要用户输入小时和分钟的示例:

    void onTap() {
      Picker(
        adapter: NumberPickerAdapter(data: <NumberPickerColumn>[
          const NumberPickerColumn(begin: 0, end: 999, suffix: Text(' hours')),
          const NumberPickerColumn(begin: 0, end: 60, suffix: Text(' minutes'), jump: 15),
        ]),
        delimiter: <PickerDelimiter>[
          PickerDelimiter(
            child: Container(
              width: 30.0,
              alignment: Alignment.center,
              child: Icon(Icons.more_vert),
            ),
          )
        ],
        hideHeader: true,
        confirmText: 'OK',
        confirmTextStyle: TextStyle(inherit: false, color: Colors.red, fontSize: 22),
        title: const Text('Select duration'),
        selectedTextStyle: TextStyle(color: Colors.blue),
        onConfirm: (Picker picker, List<int> value) {
          // You get your duration here
          Duration _duration = Duration(hours: picker.getSelectedValues()[0], minutes: picker.getSelectedValues()[1]);
        },
      ).showDialog(context);
    }
    

    【讨论】:

      猜你喜欢
      • 2022-12-12
      • 2019-01-28
      • 2021-01-17
      • 2021-09-05
      • 2014-09-14
      • 1970-01-01
      • 2021-10-23
      • 2019-04-30
      • 2019-04-30
      相关资源
      最近更新 更多