颤振持续时间用户输入

Mar*_* B. 4 user-interface user-input flutter

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

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

Vin*_*eet 8

您可以为此使用flutter_picker包。

以下代码段显示了一个需要用户输入小时和分钟的示例:

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);
}
Run Code Online (Sandbox Code Playgroud)