- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想增加 TextFormField 中 labelText 和hintText 之间的距离,而 contentPadding: EdgeInsets.fromLTRB(x, x, x, x) 根本没有帮助我,它确实应用了填充,但这些元素保持在一起。
我的预览:
最佳答案
您可以使用hintStyle 和LabelStyle 执行此操作,将高度属性设置为您想要的
你可以在图片中看到我的测试结果
代码片段
TextFormField(
decoration: const InputDecoration(
icon: Icon(Icons.person),
hintText: 'What do people call you?',
hintStyle: TextStyle(height:7, fontWeight: FontWeight.bold),
labelText: 'Name *',
labelStyle: TextStyle(height:5, fontWeight: FontWeight.bold),
),
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Invoke "debug painting" (press "p" in the console, choose the
// "Toggle Debug Paint" action from the Flutter Inspector in Android
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
// to see the wireframe for each widget.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextFormField(
decoration: const InputDecoration(
icon: Icon(Icons.person),
hintText: 'What do people call you?',
hintStyle: TextStyle(height:7, fontWeight: FontWeight.bold),
labelText: 'Name *',
labelStyle: TextStyle(height:5, fontWeight: FontWeight.bold),
),
onSaved: (String value) {
// This optional block of code can be used to run
// code when the user saves the form.
},
validator: (String value) {
return value.contains('@') ? 'Do not use the @ char.' : null;
},
),
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.display1,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
关于flutter-layout - TextFormField 中 LabelText 和 HintText 之间的更多空间(Flutter),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58001258/
请帮助解决我的 2 个问题。 第一个问题。为什么文本值消失?[已修复] @Praneeth我添加了动图 please click 我的代码就是这样用的 在我的小部件中,我调用了 UsernameTex
这是我目前面临的情况,因为我希望红色文本出现在该行的下方而不是上方,因为它看起来有点丑陋,如下所示: new Container( width: Media
当用户输入第一个 TextFormField 时,我试图更改第二个 TextFormField 的值。 TextEditingController txt1 = TextEditingControl
我正在尝试创建一个带有列的表单。 喜欢,表单 => 列 => 文本字段, TextFields 将有验证器。此外,TextFields 将进行装饰。 但是当我点击 RaisedButton 时,我找不
我需要一个带有 suffixIcon 的 textField,但是单击该图标后,我不需要打开键盘。如果没有 suffixIcon,我该如何做呢? 最佳答案 Container( child: St
当我按下按钮时,TextFormField 将被聚焦并出现键盘。如何解决这个问题? 代码如下: TextFormField( controller: code,
这是我的密码字段代码: TextFormField( obscureText: isObscure, decoration: InputDecoration( suffix: Text
目标是显示/隐藏清除 Flutter TextFormField 上的字段的 suffixIcon。只有当框中有文本时它才应该可见。 该字段如下所示: TextFormField(
我正在编写一个扫描仪应用程序,该应用程序将安装在运行 Android 的扫描仪上。应用程序内部有一个 TextFormField 等待输入扫描或粘贴在里面的文本以进行其他 API 调用。 但是我没有找
... @override Widget build(BuildContext context) { return MaterialApp( title: 'haha',
我想将充满红色背景的框移动到空框的位置。 换句话说,我想在 TextFormField 结束的点旁边插入一个容器。 这是可以在 Flutter 中实现的东西吗?还是没有办法? - 更新 我实际上想在文
当我达到的极限时TextFormField 文字消失了…… 我尝试了多个配置但仍然无法正常工作,我不知道为什么。 Dialog( shape: RoundedRectangleBord
当我写入的文本多于此输入的宽度时,我有一个电子邮件输入文本字段,其余文本不可见。当我输入此文本表单字段时,有没有办法进行水平滚动? 下图描述了我想要的行为。 编辑:我的代码 Container(
如果我启用并聚焦之前禁用的 TextFormField,我没有看到闪烁的光标。在此示例中,TextFormField 最初是禁用的,如 _enabled 状态变量所示,当您单击启用按钮时,该字段已启用
如果在我的文本表单字段上创建了一个值,我将尝试设置一个初始值。当我运行我的代码时: final apiField = TextFormField( controller: apiFieldCont
我对 Flutter 有点陌生所以我不知道这是否是更新从服务器收集的数据的“正确”方式。就我而言,我正在做的是(我的应用程序代码很长,我认为下面的描述就足够了): 让用户为给定日期创建自定义表单。 让
TL;博士 maxLength在 TextFormField有时允许超过指定限制的字符数。为什么会发生这种情况? 我正在尝试创建一个 Form将用户输入的数据提供给我的应用程序。作为其中的一部分,我有
我正在尝试重新创建此搜索输入,但是如果将其添加到较小的位置会遇到麻烦,但是如果添加prefixIcon,则高度会增加,但似乎无法控制它。 这就是我现在所拥有的。 我正在使用一行,因为我也需要在输入字段
我正在尝试使编辑字符串列表成为可能。问题是,当我通过 IconButton 删除列表项时,TextField 会重建,但不知何故仍然具有旧值。通过调试,我发现我的字符串列表已正确更新,这意味着删除的字
如果在 TextFormField 中验证发现错误消息,我该如何显示? 我正在使用 Stepper 类来处理用户注册,当尝试使用 setState 实现基本验证时,当前正在验证的文本字段中没有显示错误
我是一名优秀的程序员,十分优秀!