【问题标题】:Flutter InputDecoration - how to position the label over the border?Flutter InputDecoration - 如何将标签定位在边框上?
【发布时间】:2021-03-03 05:38:10
【问题描述】:

我有带有文本字段的颤振应用程序。我需要像这张图片一样将标签放置在边框上方。

我有两个选择:

1.把它完全写成一个新的小部件

2.使用TextFormField + InputDecoration

我尝试了第二种方式,这是我的代码:

      TextFormField(
      controller: _controller,
      decoration: InputDecoration(
                     border: OutlineInputBorder(

            borderRadius: BorderRadius.zero,
            borderSide: BorderSide(color: AppColors.borderColor, width: 1.0),
          ),
          
          floatingLabelBehavior: FloatingLabelBehavior.always,
          labelText: widget.hint
      ));

但我无法达到预期的效果。 这是可能的还是只有选项 1?

【问题讨论】:

  • 为什么不在TextFormField 上方添加另一个text 小部件,这样会更轻松

标签: flutter dart flutter-layout flutter-widget


【解决方案1】:

我更喜欢把它完全写成一个新的小部件,比如

Column(
    children:[
     Text('label'),
     TextFormField(//.....),
 ],
),

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-17
    • 1970-01-01
    • 1970-01-01
    • 2019-12-09
    • 2023-03-22
    相关资源
    最近更新 更多