Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 颤振:如何使用HintText创建文本字段,但不使用下划线?_Flutter_Dart_Textfield_Underline_Hint - Fatal编程技术网

Flutter 颤振:如何使用HintText创建文本字段,但不使用下划线?

Flutter 颤振:如何使用HintText创建文本字段,但不使用下划线?,flutter,dart,textfield,underline,hint,Flutter,Dart,Textfield,Underline,Hint,这就是我想做的: 在文本字段的flatterdocs()中,它表示可以通过向装饰传递null来删除下划线。但是,这也会消除提示文本 无论文本字段是否聚焦,我都不需要任何下划线 更新:更新了公认的答案,以反映2020年4月颤振SDK的变化。这样做: TextField( decoration: new InputDecoration.collapsed( hintText: 'Username' ), ), 或者,如果您需要图标等其他内容,请使用InputBorder.none

这就是我想做的:

在文本字段的flatterdocs()中,它表示可以通过向装饰传递
null
来删除下划线。但是,这也会消除提示文本

无论文本字段是否聚焦,我都不需要任何下划线

更新:更新了公认的答案,以反映2020年4月颤振SDK的变化。

这样做:

TextField(
  decoration: new InputDecoration.collapsed(
    hintText: 'Username'
  ),
),
或者,如果您需要图标等其他内容,请使用
InputBorder.none设置边框

InputDecoration(
    border: InputBorder.none,
    hintText: 'Username',
  ),
),

将焦点边框更改为“无”

TextField(
      decoration: new InputDecoration(
          border: InputBorder.none,
          focusedBorder: InputBorder.none,
          contentPadding: EdgeInsets.only(left: 15, bottom: 11, top: 11, right: 15),
          hintText: 'Subject'
      ),
    ),

下面是一个补充答案,其中显示了一些更完整的代码:

注:

  • 深色背景(代码未显示)为
    颜色。teal
  • InputDecoration
    还有一个
    filled
    fillColor
    属性,但我无法让它们有一个圆角半径,所以我使用了一个容器

新的颤振sdk,因为在集成了web和桌面支持之后,您需要像下面这样单独指定

TextFormField(
    cursorColor: Colors.black,
    keyboardType: inputType,
    decoration: new InputDecoration(
        border: InputBorder.none,
        focusedBorder: InputBorder.none,
        enabledBorder: InputBorder.none,
        errorBorder: InputBorder.none,
        disabledBorder: InputBorder.none,
        contentPadding:
            EdgeInsets.only(left: 15, bottom: 11, top: 11, right: 15),
        hintText: "Hint here"),
  )

我使用的是
TextField
flatter控件。我使用以下方法获得了用户键入的输入

onChanged:(value){
}

我发现没有其他答案给出边界半径,你可以简单地这样做,没有嵌套的
容器

  TextField(
    decoration: InputDecoration(
      border: OutlineInputBorder(
        borderSide: BorderSide.none,
        borderRadius: BorderRadius.circular(20),
      ),
    ),
  );
您可以根据需要使用的小部件

TextFormField(
     maxLines: 1,
     decoration: InputDecoration(
          prefixIcon: const Icon(
              Icons.search,
              color: Colors.grey,
          ),
      hintText: 'Search your trips',
      border: OutlineInputBorder(
         borderRadius: BorderRadius.all(Radius.circular(10.0)),
      ),
    ),
 ),

TextField小部件有一个属性装饰,它有一个子属性
border:InputBorder.none
。此属性将删除flift应用程序中的
TextField
文本输入底部下划线。因此,您可以将文本字段的
装饰
边框
属性设置为
InputBorder.none
,请参见此处的示例:

边框:InputBorder.none
:从文本输入小部件隐藏底部下划线

 Container(
        width: 280,
        padding: EdgeInsets.all(8.0),
        child : TextField(
                autocorrect: true,
                decoration: InputDecoration(
                border: InputBorder.none,
                hintText: 'Enter Some Text Here')
            )
    )

TextField(样式:TextStyle(颜色:Colors.black45,fontSize:18,装饰厚度:0.0))

显示时没有下划线,带有
装饰厚度:0.0

是否可以不导入
材料
包装?i、 e.对于
Cupertino
主题?我希望避免:
InputDecoration'不能分配给参数类型“BoxDecoration”
type error'此功能在v1.13.2之后被弃用。'在docsCan中,我们请将其标记为真正的解决方案?该答案与一个月前的答案有什么区别?您想要新的答案吗?如果已经提供了答案,则无需再次提交。这样做只会给未来的读者增加噪音,因为他们需要对多个类似的答案进行排序。在未来,一旦你获得了更多的声誉,你将能够超越现有的答案;这是验证方法和确认解决方案有效性的首选方法。我应该注意,有时,如果投稿人有不同的解释方法,或者想要添加更多细节,他们仍然会发布类似的建议。那太好了。这里的问题是,您似乎提供了相同的答案,但细节较少,因此它对线程没有多大贡献。
TextFormField(
     maxLines: 1,
     decoration: InputDecoration(
          prefixIcon: const Icon(
              Icons.search,
              color: Colors.grey,
          ),
      hintText: 'Search your trips',
      border: OutlineInputBorder(
         borderRadius: BorderRadius.all(Radius.circular(10.0)),
      ),
    ),
 ),
 Container(
        width: 280,
        padding: EdgeInsets.all(8.0),
        child : TextField(
                autocorrect: true,
                decoration: InputDecoration(
                border: InputBorder.none,
                hintText: 'Enter Some Text Here')
            )
    )
            Container(
         height: 50,
          // margin: EdgeInsets.only(top: 20),
          decoration: BoxDecoration(
              color: Colors.tealAccent,
              borderRadius: BorderRadius.circular(32)),
          child: TextFormField(
            cursorColor: Colors.black,
            // keyboardType: TextInputType.,
            decoration: InputDecoration(
              hintStyle: TextStyle(fontSize: 17),
              hintText: 'Search your trips',
              suffixIcon: Icon(Icons.search),
              border: InputBorder.none,
              contentPadding: EdgeInsets.all(18),
            ),
          ),
        ),