【问题标题】:I have difficulty in setting date我很难设定日期
【发布时间】:2022-11-30 17:26:45
【问题描述】:

enter image description here 我想这样做,但我做不到

enter image description here 我希望你教我

【问题讨论】:

    标签: flutter


    【解决方案1】:

    你可以通过使用DropdownButton widget来实现

    这是使用它的代码示例:

      @override
      Widget build(BuildContext context) {
        return DropdownButton<int>(
          value: dropdownValue,
          icon: const Icon(Icons.arrow_downward),
          elevation: 16,
          style: const TextStyle(color: Colors.deepPurple),
          underline: Container(
            height: 2,
            color: Colors.deepPurpleAccent,
          ),
          onChanged: (int? value) {
            // This is called when the user selects an item.
            setState(() {
              dropdownValue = value!;
            });
          },
          items: list.map<DropdownMenuItem<int>>((int value) {
            return DropdownMenuItem<int>(
              value: value,
              child: Text("$value"),
            );
          }).toList(),
        );
      }
    

    但是,我建议您使用 DatePicker 查看 documentation here,因为使用此小部件处理 flutter 中的日期会更容易。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-26
      • 1970-01-01
      • 1970-01-01
      • 2011-03-28
      • 2021-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多