【问题标题】:How can I add a container inside a textField?如何在 textField 中添加容器?
【发布时间】:2021-02-03 18:55:38
【问题描述】:

我尝试将 textField 包装成一行并向该行添加一个容器,但它会引发错误,并且表单的其余部分不会呈现。 并且使用 textField 的前缀属性也不起作用,因为当按下 textField 时会显示容器,但我希望即使 textField 不活动也能看到它。

this is the required UI for the mobile no. field I'm trying to build

【问题讨论】:

    标签: flutter dart


    【解决方案1】:
    Container(
      decoration: BoxDecoration(
        color: Colors.grey[200],
        borderRadius: BorderRadius.circular(8),
      ),
      child: Row(
        children: [
          Container(
            height: 50,
            alignment: Alignment.center,
            padding: const EdgeInsets.symmetric(
              horizontal: 8,
            ),
            decoration: BoxDecoration(
              color: Colors.blue,
              borderRadius: BorderRadius.only(
                topLeft: Radius.circular(8),
                bottomLeft: Radius.circular(8),
              ),
            ),
            child: Text(
              "+91",
              style: TextStyle(
                color: Colors.white,
              ),
            ),
          ),
          Expanded(
            child: Padding(
              padding: const EdgeInsets.symmetric(
                horizontal: 12,
              ),
              child: TextField(
                decoration: InputDecoration(
                  border: InputBorder.none,
                  hintText: "Mobile No."
                ),
              ),
            ),
          )
        ],
      ),
    )
    

    结果:

    【讨论】:

      猜你喜欢
      • 2016-04-02
      • 2020-07-05
      • 2019-09-22
      • 2021-09-13
      • 2015-11-02
      • 1970-01-01
      • 2018-10-05
      • 2020-05-12
      • 1970-01-01
      相关资源
      最近更新 更多