1

我是一个 ios 开发者,刚接触 Flutter。在我的应用程序中,我有 TextFormField,其输入类型是选择器中提供的选项。我正在努力将选择器视图显示为输入视图而不是键盘。我想要的输出如下

图片链接

4

1 回答 1

1
TextEditingController _controller = TextEditingController();

 Future<void> _selectedNumber(BuildContext context) async {
    int number = await showCupertinoModalPopup(
      context: context,
      builder: (context) => Container(
        height: 250,
        child: CupertinoPicker(
          itemExtent: 50,
          onSelectedItemChanged: (int value) {
            _controller.text = (value + 1).toString();
          },
          children: numbers
              .map(
                (number) => Text(number.toString()),
              )
              .toList(),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: GestureDetector(
          onTap: () => _selectedNumber(context),
          child: AbsorbPointer(
            child: TextFormField(
              keyboardType: TextInputType.datetime,
              controller: _controller,
              decoration: InputDecoration(
                hintText: 'Select A Number',
                prefixIcon: Icon(
                  Icons.format_list_numbered,
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}


这是你想要的?

于 2020-04-03T04:22:23.507 回答