【问题标题】:Use cupertino picker instead of keyboard while inputting a textformfield flutter输入 textformfield 颤动时使用 cupertino 选择器而不是键盘
【发布时间】:2020-07-15 04:48:41
【问题描述】:

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

image link

【问题讨论】:

    标签: flutter textfield inputview pickerview cupertinopicker


    【解决方案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-10-31
    • 1970-01-01
    • 1970-01-01
    • 2011-06-14
    • 2021-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-26
    相关资源
    最近更新 更多