Input 输入框
输入框用于接收用户输入的内容。
何时使用
当需要用户输入内容时使用,支持文本、密码和数字类型的输入。
代码演示
import 'package:antd_flutter_example/demo_block.dart';
import 'package:flutter/material.dart';
import 'package:trionesdev_antd_mobile/trionesdev_antd_mobile.dart';
class InputPage extends StatefulWidget {
const InputPage({super.key});
@override
State<StatefulWidget> createState() => _InputPageState();
}
class _InputPageState extends State<InputPage> {
@override
Widget build(BuildContext context) {
return AntScaffold(
appBar: AntAppBar(title: Text('Input 输入框')),
body: SingleChildScrollView(
child: Column(
spacing: 10,
children: [
DemoBlock(
title: "普通使用",
child: AntInput(placeholder: "请输入内容"),
),
DemoBlock(
title: "类型",
child: Column(
children: [
AntInput(
type: AntInputType.password,
placeholder: "请输入内容",
// height: 24,
),
],
),
),
DemoBlock(
title: "变体",
child: Column(
spacing: 10,
children: [
AntInput(
placeholder: "outlined",
variant: AntInputVariant.outlined,
),
AntInput(
placeholder: "filled",
variant: AntInputVariant.filled,
),
AntInput(
placeholder: "borderless",
variant: AntInputVariant.borderless,
),
AntInput(
placeholder: "underlined",
variant: AntInputVariant.underlined,
),
],
),
),
DemoBlock(
title: "对齐方式",
child: Column(
spacing: 10,
children: [
AntInput(
placeholder: "左对齐",
align: AntInputAlign.left,
variant: AntInputVariant.outlined,
),
AntInput(
placeholder: "右对齐",
align: AntInputAlign.right,
variant: AntInputVariant.outlined,
),
],
),
),
DemoBlock(
title: "只读模式",
child: AntInput(
placeholder: "只读输入框",
value: "这是只读内容",
readOnly: true,
variant: AntInputVariant.outlined,
),
),
DemoBlock(
title: "自定义样式",
child: Column(
spacing: 10,
children: [
AntInput(
style: StateStyle(
style: Style(
borderRadius: 0,
borderBottom: StyleBorder(
color: Colors.blue,
width: 2,
style: BorderStyle.solid,
),
),
),
placeholder: "请输入内容",
),
AntInput(
decoration: BoxDecoration(
border: Border.all(color: Colors.black),
),
padding: EdgeInsets.symmetric(horizontal: 4),
placeholder: "请输入内容",
size: AntSize.large,
suffix: Icon(Icons.add),
// height: 24,
),
],
),
),
],
),
),
);
}
}
API
输入框的属性说明如下:
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| size | 组件大小 | AntSize | middle |
| readOnly | 是否只读 | bool | false |
| height | 输入框高度 | double? | null |
| placeholder | 提示文本 | String? | null |
| type | 输入框类型 | AntInputType? | text |
| prefix | 前缀 | Widget? | null |
| suffix | 后缀 | Widget? | null |
| value | 当前值 | String? | null |
| defaultValue | 默认值 | String? | null |
| disabled | 是否禁用 | bool | false |
| onChange | 值改变回调 | ValueChanged<String>? | null |
| decoration | 输入框装饰 | BoxDecoration? | null |
| padding | 内边距 | EdgeInsetsGeometry? | null |
| style | 样式 | StateStyle? | null |
| onBlur | 失去焦点回调 | ValueGetter<void>? | null |
| onFocus | 获得焦点回调 | ValueGetter<void>? | null |
| align | 对齐方式 | AntInputAlign? | null |
| variant | 输入框样式 | AntInputVariant? | borderless |
| borderRadius | 边框圆角 | BorderRadius? | null |
| border | 边框 | BorderSide? | null |
| focusedBorder | 选中时的边框 | BorderSide? | null |
AntInputType枚举值
| 值 | 说明 |
|---|---|
| text | 文本输入 |
| password | 密码输入 |
| number | 数字输入 |
AntInputAlign枚举值
| 值 | 说明 |
|---|---|
| left | 左齐 |
| right | 右齐 |
AntInputVariant枚举值
| 值 | 说明 |
|---|---|
| outlined | 描样式 |
| borderless | 无边框样式 |
| filled | 样式 |
| underlined | 下划线样式 |
AntSize枚举值
| 值 | 说明 | 尺寸 |
|---|---|---|
| small | 小尺寸 | 高24px |
| middle | 中尺寸 | 高32px |
| large | 大尺寸 | 高40px |