一、Text

1.1 构造函数:

  1. const Text(
  2. String this.data, {
  3. Key? key,
  4. this.style,
  5. this.strutStyle,
  6. this.textAlign,
  7. this.textDirection,
  8. this.locale,
  9. this.softWrap,
  10. this.overflow,
  11. this.textScaleFactor,
  12. this.maxLines,
  13. this.semanticsLabel,
  14. this.textWidthBasis,
  15. this.textHeightBehavior,
  16. })

1.2 主要参数说明:

style:用于指定文本显示的样式如颜色、字体、粗细、背景等
textAlign:文本对齐方式

  • TextAlign.left:左对齐。
  • TextAlign.right:右对齐。
  • TextAlign.center:居中对齐。
  • TextAlign.start:文字开始的方向对齐,如果文字方向是从左到右,就左对齐,反之则右对齐。
  • TextAlign.end:文字开始的相反方向对齐,如果文字方向是从左到右,就右对齐,反之则左对齐。
  • TextAlign.justify:两端对齐,当文字不足一行时,中间的文字会被拉伸。

textDirection:用于控制文字的显示方向

  • TextDirection.ltr:文字方向从左到右。
  • TextDirection.rtl:文字方向从右到左。

overflow:用于表示文本的截断方式

  • TextOverflow.ellipsis:多余文本截断后以省略符表示。
  • TextOverflow.clip:剪切多余文本,多余文本不显示。
  • TextOverflow.fade:将多余的文本设为透明。

textScaleFactor:控制文本缩放
maxLines:最大显示行数

1.3 代码示例:

  1. Widget _buildText() {
  2. return const Text(
  3. "《望庐山瀑布》 李白 日照香炉生紫烟,遥看瀑布挂前川。飞流直下三千尺,疑是银河落九天。",
  4. style: TextStyle(
  5. color: Color(0xFFFF5C5C),
  6. fontSize: 16,
  7. ),
  8. textAlign: TextAlign.center,
  9. textDirection: TextDirection.ltr,
  10. // textScaleFactor: 2,
  11. // overflow: TextOverflow.ellipsis,
  12. // maxLines: 1,
  13. );
  14. }

1.4 显示效果:

WX20220705-120339@2x.png

二、TextSpan

Text 的所有文本内容只能按同一种样式,如果我们需要对一个 Text 内容的不同部分按照不同的样式显示,可以使用TextSpan。

2.1 构造函数:

  1. const TextSpan({
  2. this.text,
  3. this.children,
  4. TextStyle? style,
  5. this.recognizer,
  6. MouseCursor? mouseCursor,
  7. this.onEnter,
  8. this.onExit,
  9. this.semanticsLabel,
  10. this.locale,
  11. this.spellOut,
  12. })

2.2 主要参数说明:

text:文本内容
children:一个TextSpan的数组,TextSpan可以包括其他TextSpan
style:用于指定文本显示的样式如颜色、字体、粗细、背景等
recognizer:文本片段上手势识别处理

2.3 代码示例:

  1. Widget _buildTextSpan() {
  2. return Text.rich(
  3. TextSpan(
  4. children: [
  5. TextSpan(
  6. text: "《望庐山瀑布》 李白",
  7. style: const TextStyle(color: Colors.red, fontSize: 18),
  8. recognizer: TapGestureRecognizer()
  9. ..onTap = () {
  10. debugPrint("《望庐山瀑布》 李白");
  11. },
  12. ),
  13. TextSpan(
  14. text: "日照香炉生紫烟,遥看瀑布挂前川。",
  15. style: const TextStyle(color: Colors.green, fontSize: 16),
  16. recognizer: TapGestureRecognizer()
  17. ..onTap = () {
  18. debugPrint("日照香炉生紫烟,遥看瀑布挂前川。");
  19. },
  20. ),
  21. TextSpan(
  22. text: "飞流直下三千尺,疑是银河落九天。",
  23. style: const TextStyle(color: Colors.blue, fontSize: 16),
  24. recognizer: TapGestureRecognizer()
  25. ..onTap = () {
  26. debugPrint("飞流直下三千尺,疑是银河落九天。");
  27. },
  28. ),
  29. ],
  30. ),
  31. );
  32. }

2.4 显示效果:

WX20220705-162653@2x.png

三、Button

3.1 ElevatedButton

ElevatedButton “漂浮”按钮,它默认带有阴影和灰色背景。按下后,阴影会变大

3.1.1 构造函数:

  1. const ElevatedButton({
  2. Key? key,
  3. required VoidCallback? onPressed,
  4. VoidCallback? onLongPress,
  5. ValueChanged<bool>? onHover,
  6. ValueChanged<bool>? onFocusChange,
  7. ButtonStyle? style,
  8. FocusNode? focusNode,
  9. bool autofocus = false,
  10. Clip clipBehavior = Clip.none,
  11. required Widget? child,
  12. })

3.1.2 主要参数说明:

onPressed:点击回调
onLongPress:长按回调
child:子组件
style:样式

  1. const ButtonStyle({
  2. this.textStyle,
  3. this.backgroundColor, //背景色
  4. this.foregroundColor, //前景色
  5. this.overlayColor, // 高亮色,按钮处于focused, hovered, or pressed时的颜色
  6. this.shadowColor, // 阴影颜色
  7. this.elevation, // 阴影值
  8. this.padding, // padding
  9. this.minimumSize, //最小尺寸
  10. this.fixedSize,
  11. this.maximumSize,
  12. this.side, //边框
  13. this.shape, //形状
  14. this.mouseCursor, //鼠标指针的光标进入或悬停在此按钮的[InkWell]上时。
  15. this.visualDensity, // 按钮布局的紧凑程度
  16. this.tapTargetSize, // 响应触摸的区域
  17. this.animationDuration, //[shape]和[elevation]的动画更改的持续时间。
  18. this.enableFeedback,
  19. this.alignment,
  20. this.splashFactory,
  21. })

3.1.3 代码示例:

  1. Widget _buildElevatedButton() {
  2. return Center(
  3. child: ElevatedButton(
  4. child: const Text("ElevatedButton"),
  5. onPressed: () {
  6. debugPrint("_buildElevatedButton");
  7. },
  8. ),
  9. );
  10. }

3.1.4 显示效果:

WX20220705-224404@2x.png

3.2 TextButton

TextButton文本按钮,默认背景透明并不带阴影。按下后,会有背景色

3.2.1 构造函数:

  1. const TextButton({
  2. Key? key,
  3. required VoidCallback? onPressed,
  4. VoidCallback? onLongPress,
  5. ValueChanged<bool>? onHover,
  6. ValueChanged<bool>? onFocusChange,
  7. ButtonStyle? style,
  8. FocusNode? focusNode,
  9. bool autofocus = false,
  10. Clip clipBehavior = Clip.none,
  11. required Widget child,
  12. })

3.2.2 主要参数说明:

onPressed:点击回调
onLongPress:长按回调
child:子组件
style:样式

3.2.3 代码示例:

  1. Widget _buildTextButton() {
  2. return Center(
  3. child: TextButton(
  4. child: const Text("TextButton"),
  5. onPressed: () {
  6. debugPrint("_buildTextButton");
  7. },
  8. ),
  9. );
  10. }

3.2.4 显示效果:

WX20220706-010259@2x.png

3.3 OutlinedButton

OutlinedButton默认有一个边框,不带阴影且背景透明。按下后,边框颜色会变亮、同时出现背景和阴影(较弱)

3.3.1 构造函数:

  1. const OutlinedButton({
  2. Key? key,
  3. required VoidCallback? onPressed,
  4. VoidCallback? onLongPress,
  5. ValueChanged<bool>? onHover,
  6. ValueChanged<bool>? onFocusChange,
  7. ButtonStyle? style,
  8. FocusNode? focusNode,
  9. bool autofocus = false,
  10. Clip clipBehavior = Clip.none,
  11. required Widget child,
  12. })

3.3.2 主要参数说明:

onPressed:点击回调
onLongPress:长按回调
child:子组件
style:样式

3.3.3 代码示例:

  1. Widget _buildOutlinedButton() {
  2. return Center(
  3. child: OutlinedButton(
  4. child: const Text("OutlinedButton"),
  5. onPressed: () {
  6. debugPrint("_buildOutlinedButton");
  7. },
  8. ),
  9. );
  10. }

3.3.4 显示效果:

WX20220706-010642@2x.png

3.4 IconButton

IconButton是一个可点击的Icon,不包括文字,默认没有背景,点击后会出现背景

3.4.1 构造函数:

  1. const IconButton({
  2. Key? key,
  3. this.iconSize,
  4. this.visualDensity,
  5. this.padding = const EdgeInsets.all(8.0),
  6. this.alignment = Alignment.center,
  7. this.splashRadius,
  8. this.color,
  9. this.focusColor,
  10. this.hoverColor,
  11. this.highlightColor,
  12. this.splashColor,
  13. this.disabledColor,
  14. required this.onPressed,
  15. this.mouseCursor,
  16. this.focusNode,
  17. this.autofocus = false,
  18. this.tooltip,
  19. this.enableFeedback = true,
  20. this.constraints,
  21. required this.icon,
  22. })

3.4.2 主要参数说明:

iconSize:icon大小
color:icon 颜色
highlightColor:按下去高亮的颜色
splashColor:点击时闪过的颜色
disabledColor:icon 不可点击颜色,onPressed == null 时生效
onPressed:点击回调
tooltip:长按按钮时的组件提示语句
icon:icon组件

3.4.3 代码示例:

  1. Widget _buildIconButton() {
  2. return Center(
  3. child: IconButton(
  4. tooltip: "IconButton",
  5. icon: const Icon(Icons.add_circle_rounded),
  6. onPressed: () {
  7. debugPrint("_buildIconButton");
  8. },
  9. ),
  10. );
  11. }

3.4.4 显示效果:

WX20220706-012051@2x.png

3.5 带图标的按钮

ElevatedButton、TextButton、OutlineButton都有一个icon 构造函数,通过它可以轻松创建带图标的按

  1. factory ElevatedButton.icon({
  2. Key? key,
  3. required VoidCallback? onPressed, //点击响应
  4. VoidCallback? onLongPress,
  5. ValueChanged<bool>? onHover,
  6. ValueChanged<bool>? onFocusChange,
  7. ButtonStyle? style,
  8. FocusNode? focusNode,
  9. bool? autofocus,
  10. Clip? clipBehavior,
  11. required Widget icon, //Icon组件
  12. required Widget label, //文本组件
  13. })
  14. factory TextButton.icon({
  15. Key? key,
  16. required VoidCallback? onPressed, //点击响应
  17. VoidCallback? onLongPress,
  18. ValueChanged<bool>? onHover,
  19. ValueChanged<bool>? onFocusChange,
  20. ButtonStyle? style,
  21. FocusNode? focusNode,
  22. bool? autofocus,
  23. Clip? clipBehavior,
  24. required Widget icon, //Icon组件
  25. required Widget label, //文本组件
  26. })
  27. factory OutlinedButton.icon({
  28. Key? key,
  29. required VoidCallback? onPressed, //点击响应
  30. VoidCallback? onLongPress,
  31. ButtonStyle? style,
  32. FocusNode? focusNode,
  33. bool? autofocus,
  34. Clip? clipBehavior,
  35. required Widget icon, //Icon组件
  36. required Widget label, //文本组件
  37. })

四、Image

Flutter 中通过Image组件来加载并显示图片,Image的数据源可以是asset、文件、内存以及网络。

1.1 构造函数:

  1. const Image({
  2. Key? key,
  3. required this.image, // AssetImage从Asset中加载图片的 ImageProvider,NetworkImage从网络加载图片的 ImageProvider。
  4. this.frameBuilder,
  5. this.loadingBuilder,
  6. this.errorBuilder,
  7. this.semanticLabel,
  8. this.excludeFromSemantics = false,
  9. this.width, //图片宽度
  10. this.height, //图片高度
  11. this.color, //图片的混合色值
  12. this.opacity,
  13. this.colorBlendMode, //混合模式
  14. this.fit, //缩放模式
  15. this.alignment = Alignment.center, //对齐方式
  16. this.repeat = ImageRepeat.noRepeat, //重复方式
  17. this.centerSlice,
  18. this.matchTextDirection = false,
  19. this.gaplessPlayback = false,
  20. this.isAntiAlias = false,
  21. this.filterQuality = FilterQuality.low,
  22. })

Image也提供了一个快捷的构造函数Image.asset用于从asset中加载、显示图片

  1. Image.asset(
  2. String name, {
  3. Key? key,
  4. AssetBundle? bundle,
  5. this.frameBuilder,
  6. this.errorBuilder,
  7. this.semanticLabel,
  8. this.excludeFromSemantics = false,
  9. double? scale,
  10. this.width,
  11. this.height,
  12. this.color,
  13. this.opacity,
  14. this.colorBlendMode,
  15. this.fit,
  16. this.alignment = Alignment.center,
  17. this.repeat = ImageRepeat.noRepeat,
  18. this.centerSlice,
  19. this.matchTextDirection = false,
  20. this.gaplessPlayback = false,
  21. this.isAntiAlias = false,
  22. String? package,
  23. this.filterQuality = FilterQuality.low,
  24. int? cacheWidth,
  25. int? cacheHeight,
  26. })

Image也提供了一个快捷的构造函数Image.network用于从网络加载、显示图片

  1. Image.network(
  2. String src, {
  3. Key? key,
  4. double scale = 1.0,
  5. this.frameBuilder,
  6. this.loadingBuilder,
  7. this.errorBuilder,
  8. this.semanticLabel,
  9. this.excludeFromSemantics = false,
  10. this.width,
  11. this.height,
  12. this.color,
  13. this.opacity,
  14. this.colorBlendMode,
  15. this.fit,
  16. this.alignment = Alignment.center,
  17. this.repeat = ImageRepeat.noRepeat,
  18. this.centerSlice,
  19. this.matchTextDirection = false,
  20. this.gaplessPlayback = false,
  21. this.filterQuality = FilterQuality.low,
  22. this.isAntiAlias = false,
  23. Map<String, String>? headers,
  24. int? cacheWidth,
  25. int? cacheHeight,
  26. })

1.2 主要参数说明:

image:AssetImage从Asset中加载图片的 ImageProvider,NetworkImage从网络加载图片的 ImageProvider。
width:图片宽度
height:图片高度
color:图片的混合色值
colorBlendMode:混合模式
fit:缩放模式

  1. BoxFit.contain 全图居中显示但不充满,显示原比例
  2. BoxFit.cover 图片可能拉伸,也可能裁剪,但是充满容器
  3. BoxFit.fill 全图显示且填充满,图片可能会拉伸
  4. BoxFit.fitHeight 图片可能拉伸,可能裁剪,高度充满
  5. BoxFit.fitWidth 图片可能拉伸,可能裁剪,宽度充满
  6. BoxFit.scaleDown 效果和contain差不多, 但是只能缩小图片,不能放大图片

alignment:对齐方式

  1. Alignment.topLeft:垂直靠顶部水平靠左对齐
  2. Alignment.topCenter:垂直靠顶部水平居中对齐
  3. Alignment.topRight:垂直靠顶部水平靠右对齐
  4. Alignment.centerLeft:垂直居中水平靠左对齐
  5. Alignment.center:垂直和水平居中都对齐
  6. Alignment.centerRight:垂直居中水平靠右对齐
  7. Alignment.bottomLeft:垂直靠底部水平靠左对齐
  8. Alignment.bottomCenter:垂直靠底部水平居中对齐
  9. Alignment.bottomRight:垂直靠底部水平靠右对齐

repeat:重复方式

  1. ImageRepeat.noRepeat不重复
  2. ImageRepeat.repeat XY 轴都重复
  3. ImageRepeat.repeatX只在 X 轴重复
  4. ImageRepeat.repeatY只在 Y 轴重复

1.3 代码示例:

1.4 显示效果:

五、TextField

TextField用于文本输入

1.1 构造函数:

  1. const TextField({
  2. Key? key,
  3. this.controller,
  4. this.focusNode,
  5. this.decoration = const InputDecoration(),
  6. TextInputType? keyboardType,
  7. this.textInputAction,
  8. this.textCapitalization = TextCapitalization.none,
  9. this.style,
  10. this.strutStyle,
  11. this.textAlign = TextAlign.start,
  12. this.textAlignVertical,
  13. this.textDirection,
  14. this.readOnly = false,
  15. ToolbarOptions? toolbarOptions,
  16. this.showCursor,
  17. this.autofocus = false,
  18. this.obscuringCharacter = '•',
  19. this.obscureText = false,
  20. this.autocorrect = true,
  21. SmartDashesType? smartDashesType,
  22. SmartQuotesType? smartQuotesType,
  23. this.enableSuggestions = true,
  24. this.maxLines = 1,
  25. this.minLines,
  26. this.expands = false,
  27. this.maxLength,
  28. this.maxLengthEnforced = true,
  29. this.maxLengthEnforcement,
  30. this.onChanged,
  31. this.onEditingComplete,
  32. this.onSubmitted,
  33. this.onAppPrivateCommand,
  34. this.inputFormatters,
  35. this.enabled,
  36. this.cursorWidth = 2.0,
  37. this.cursorHeight,
  38. this.cursorRadius,
  39. this.cursorColor,
  40. this.selectionHeightStyle = ui.BoxHeightStyle.tight,
  41. this.selectionWidthStyle = ui.BoxWidthStyle.tight,
  42. this.keyboardAppearance,
  43. this.scrollPadding = const EdgeInsets.all(20.0),
  44. this.dragStartBehavior = DragStartBehavior.start,
  45. this.enableInteractiveSelection = true,
  46. this.selectionControls,
  47. this.onTap,
  48. this.mouseCursor,
  49. this.buildCounter,
  50. this.scrollController,
  51. this.scrollPhysics,
  52. this.autofillHints = const <String>[],
  53. this.clipBehavior = Clip.hardEdge,
  54. this.restorationId,
  55. this.enableIMEPersonalizedLearning = true,
  56. })
  1. const TextField({
  2. Key? key,
  3. this.controller, //控制器,可以控制 textField 的输入内容,也可以监听 textField 改变
  4. this.focusNode, //焦点控制
  5. this.decoration = const InputDecoration(), //TextField组件的装饰(外观)参数,类型是InputDecoration
  6. TextInputType? keyboardType, //TextInputType,键盘类型
  7. this.textInputAction, //键盘完成按钮样式
  8. this.textCapitalization = TextCapitalization.none, //大小写,默认为 TextCapitalization.none
  9. this.style, //字体样式
  10. this.strutStyle, //字体的布局样式
  11. this.textAlign = TextAlign.start, //文字对齐方式,默认为 TextAlign.start
  12. this.textAlignVertical, //文字纵轴对齐方式
  13. this.textDirection, //TextDirection.ltr 是居左,TextDirection.rtl 是居右,和 textAlign 效果一致
  14. this.readOnly = false, //只读属性,默认为 false
  15. ToolbarOptions? toolbarOptions, //长按时弹出的按钮设置,(如赋值,粘贴,全部选中等)
  16. this.showCursor, //是否显示光标,默认为 true
  17. this.autofocus = false, //是否自动聚焦,默认为 false
  18. this.obscuringCharacter = '•', //加密输入时的替换字符,默认为 '•'
  19. this.obscureText = false, //是否加密,默认为 false
  20. this.autocorrect = true, //是否自动更正,默认为 true
  21. SmartDashesType? smartDashesType, //SmartDashesType 智能替换破折号,例如连续输入三个'-' 会自动替换成一个'——',当 obseretext == true 时,smartDashesType 默认不可用
  22. SmartQuotesType? smartQuotesType, //SmartQuotesType 智能替换引号,根据文字情况智能替换为左引号或者右引号,当 obseretext == true 时,SmartQuotesType 默认不可用
  23. this.enableSuggestions = true, //是否在用户输入时显示输入建议,此标志仅影响Android,默认为 true
  24. this.maxLines = 1, //最大行数
  25. this.minLines, //最小行数
  26. this.expands = false, //是否填充父控件,默认为 false
  27. this.maxLength, //最大长度
  28. this.maxLengthEnforced = true, //是否强制限制,或者只提供字符计数器和警告,默认为 true
  29. this.maxLengthEnforcement, //
  30. this.onChanged, //输入框文字改变回调
  31. this.onEditingComplete, //输入框完成回调
  32. this.onSubmitted, //提交按钮点击回调
  33. this.onAppPrivateCommand,
  34. this.inputFormatters, //格式化输入,注意这里比 onChanged 先执行
  35. this.enabled, //是否可用
  36. this.cursorWidth = 2.0, //光标宽度,默认为 2.0
  37. this.cursorHeight, //光标高度
  38. this.cursorRadius, //光标圆角
  39. this.cursorColor, //光标颜色
  40. this.selectionHeightStyle = ui.BoxHeightStyle.tight, //选中高度样式,默认为 ui.BoxHeightStyle.tight
  41. this.selectionWidthStyle = ui.BoxWidthStyle.tight, //选中宽度样式,默认为 ui.BoxWidthStyle.tight
  42. this.keyboardAppearance, //键盘外观,此设置仅适用于iOS设备,iOS的白色以及黑色风格键盘
  43. this.scrollPadding = const EdgeInsets.all(20.0), //滚动后距离边缘的距离,默认为 EdgeInsets.all(20.0)
  44. this.dragStartBehavior = DragStartBehavior.start, //启动阻力,默认为 DragStartBehavior.start
  45. this.enableInteractiveSelection = true, //默认为True,如果为false,则大多数辅助功能支持选择文本、复制和粘贴,移动插入符号将被禁用。
  46. this.selectionControls,
  47. this.onTap, //点击事件
  48. this.mouseCursor, //鼠标悬停,Web可以了解
  49. this.buildCounter, //InputDecorator.counter 自定义小工具
  50. this.scrollController, //滚动控制器
  51. this.scrollPhysics, //滚动物理效果
  52. this.autofillHints = const <String>[], //自动填充
  53. this.clipBehavior = Clip.hardEdge,
  54. this.restorationId,
  55. this.enableIMEPersonalizedLearning = true,
  56. })

decoration:用于设置输入框相关的样式
icon:设置左边显示的图标
labelText:在输入框上面显示一个提示的文本
hintText:显示提示的占位文字
border:输入框的边框,默认底部有一个边框,可以通过InputBorder.none删除掉
filled:是否填充输入框,默认为false
fillColor:输入框填充的颜色

textInputAction参数控制软键盘右下角的按键,说明如下:
none:android上显示返回键,ios不支持。
unspecified:让操作系统自己决定哪个合适,一般情况下,android显示“完成”或者“返回”。
done:android显示代表“完成”的按钮,ios显示“Done”(中文:完成)。
go:android显示表达用户去向目的地的图标,比如向右的箭头,ios显示“Go”(中文:前往)。
search:android显示表达搜索的按钮,ios显示”Search”(中文:搜索)。
send:android显示表达发送意思的按钮,比如“纸飞机”按钮,ios显示”Send”(中文:发送)。
next:android显示表达“前进”的按钮,比如“向右的箭头”,ios显示”Next”(中文:下一项)。
previous:android显示表达“后退”的按钮,比如“向左的箭头”,ios不支持。
continueAction:android 不支持,ios仅在ios9.0+显示”Continue”(中文:继续)。
join:Android和ios显示”Join”(中文:加入)。
route:android 不支持,ios显示”Route”(中文:路线)。
emergencyCall:android 不支持,ios显示”Emergency Call”(中文:紧急电话)。
newline:android显示表达“换行”的按钮,ios显示”换行“。

1.2 主要参数说明:

controller:控制器,可以控制 textField 的输入内容,也可以监听 textField 改变
focusNode:焦点控制
decoration:TextField组件的装饰(外观)参数,类型是InputDecoration
keyboardType:TextInputType,键盘类型
textInputAction:键盘完成按钮样式
textCapitalization:大小写,默认为 TextCapitalization.none
style:字体样式
strutStyle:字体的布局样式
textAlign:文字对齐方式,默认为 TextAlign.start
textAlignVertical:文字纵轴对齐方式
textDirection:TextDirection.ltr 是居左,TextDirection.rtl 是居右,和 textAlign 效果一致
readOnly :只读属性,默认为 false
toolbarOptions:长按时弹出的按钮设置,(如赋值,粘贴,全部选中等)
showCursor:是否显示光标,默认为 true
autofocus:是否自动聚焦,默认为 false
obscuringCharacter:加密输入时的替换字符,默认为 ‘•’
obscureText = false:是否加密,默认为 false
autocorrect:是否自动更正,默认为 true
smartDashesType:SmartDashesType 智能替换破折号,例如连续输入三个’-‘ 会自动替换成一个’——‘,当 obseretext == true 时,smartDashesType 默认不可用
smartQuotesType:SmartQuotesType 智能替换引号,根据文字情况智能替换为左引号或者右引号,当 obseretext == true 时,SmartQuotesType 默认不可用
enableSuggestions:是否在用户输入时显示输入建议,此标志仅影响Android,默认为 true
maxLines:最大行数
minLines:最小行数
expands:是否填充父控件,默认为 false
maxLength:最大长度
maxLengthEnforced = true:是否强制限制,或者只提供字符计数器和警告,默认为 true
onChanged:输入框文字改变回调
onEditingComplete:输入框完成回调
onSubmitted:提交按钮点击回调
inputFormatters:格式化输入,注意这里比 onChanged 先执行
enabled:是否可用
cursorWidth:光标宽度,默认为 2.0
cursorHeight:光标高度
cursorRadius:光标圆角
cursorColor:光标颜色
selectionHeightStyle:选中高度样式,默认为 ui.BoxHeightStyle.tight
selectionWidthStyle:选中宽度样式,默认为 ui.BoxWidthStyle.tight
keyboardAppearance:键盘外观,此设置仅适用于iOS设备,iOS的白色以及黑色风格键盘
scrollPadding:滚动后距离边缘的距离,默认为 EdgeInsets.all(20.0)
dragStartBehavior:启动阻力,默认为 DragStartBehavior.start
enableInteractiveSelection:默认为True,如果为false,则大多数辅助功能支持选择文本、复制和粘贴,移动插入符号将被禁用。
onTap:点击事件
mouseCursor:鼠标悬停,Web可以了解
buildCounter:InputDecorator.counter 自定义小工具
scrollController:滚动控制器
scrollPhysics:滚动物理效果
autofillHints:自动填充

1.3 代码示例:

1.4 显示效果: