【问题标题】:How to create a fixed Text label in flutter如何在颤振中创建固定的文本标签
【发布时间】:2021-03-05 08:22:44
【问题描述】:

我想在一个保持固定位置的文本字段上创建一个标签。我的手机上有一个应用程序,其标签如下所示,并且正在尝试设计类似的东西:

正如所见,无论是否有人在字段中键入,标签总是固定在适当的位置。我在Customer Contact Field 中输入了“Jay” 使用我当前的代码,标签从字段内部开始,然后移动到边界处。或者也许它不可能用颤振?

child:TextField(
       decoration: InputDecoration(
       labelText: 'Customer Contact')),

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    您可以将TextTextField 添加到Column 小部件中以实现此目的:

        Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            Text('Customer Contact', textAlign: TextAlign.left),
            TextField(
              cursorColor: Colors.white,
              decoration: InputDecoration(hintText: 'Enter here'),
            )
          ],
        );
    

    【讨论】:

      【解决方案2】:

      您应该将所有内容保留在 TextField 中,以便它可以自动管理验证流样式。

      InputDecoration(
          contentPadding: EdgeInsets.zero,
          label: Container(
              child: Text(
                  widget.title,
              ),
          ),
          floatingLabelBehavior: FloatingLabelBehavior.always,
      )
      

      【讨论】:

        猜你喜欢
        • 2022-10-09
        • 1970-01-01
        • 1970-01-01
        • 2012-01-12
        • 2020-11-23
        • 2020-04-18
        • 2011-08-27
        • 2021-04-02
        • 2020-02-18
        相关资源
        最近更新 更多