Skip to main content

表单操作的组件

开关

Switch(
value: false,
onChanged: (value) {},
),

复选框

Checkbox(
value: false,
activeColor: Colors.red,
onChanged: (value) {},
)

输入框

TextEditingController _unameController = TextEditingController(); // 定义一个controller

TextField(
autofocus: true,
controller: _unameController, // 设置输入框controller
decoration: InputDecoration(
labelText: "用户名",
hintText: "用户名或邮箱",
prefixIcon: Icon(Icons.person)),
),
TextField(
decoration: InputDecoration(
labelText: "密码",
hintText: "您的登录密码",
prefixIcon: Icon(Icons.lock)),
obscureText: true,
onChanged: (value) { // 监听文本变化
print(value);
},
),

print(_unameController.text); // 获取输入框内容