flutter Form表单
import 'package:flutter/material.dart';
class FormDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('FormDemo'),
elevation: 0.0,
),
body: Theme(
data: Theme.of(context).copyWith(
primaryColor: Colors.black,
),
child: Container(
padding: EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
RegisterForm(),
],
),
),
),
);
}
}
class RegisterForm extends StatefulWidget {
@override
RegisterFormState createState() => RegisterFormState();
}
class RegisterFormState extends State<RegisterForm> {
final registerFormKey = GlobalKey<FormState>();
String username, password;
bool autovalidate = false;
void submitRegisterForm() {
if (registerFormKey.currentState.validate()) {
registerFormKey.currentState.save();
debugPrint('username: $username');
debugPrint('password: $password');
Scaffold.of(context).showSnackBar(
SnackBar(
content: Text('Registering...'),
)
);
} else {
setState(() {
autovalidate = true;
});
}
}
String validateUsername(value) {
if (value.isEmpty) {
return 'Username is required.';
}
return null;
}
String validatePassword(value) {
if (value.isEmpty) {
return 'Password is required.';
}
return null;
}
@override
Widget build(BuildContext context) {
return Form(
key: registerFormKey,
child: Column(
children: <Widget>[
TextFormField(
decoration: InputDecoration(
labelText: 'Username',
helperText: '',
),
onSaved: (value) {
username = value;
},
validator: validateUsername,
autovalidate: autovalidate,
),
TextFormField(
obscureText: true,
decoration: InputDecoration(
labelText: 'Password',
helperText: '',
),
onSaved: (value) {
password = value;
},
validator: validatePassword,
autovalidate: autovalidate,
),
SizedBox(height: 32.0,),
Container(
width: double.infinity,
child: RaisedButton(
color: Theme.of(context).accentColor,
child: Text('Register', style: TextStyle(color: Colors.white)),
elevation: 0.0,
onPressed: submitRegisterForm,
),
),
],
),
);
}
}
class TextFieldDemo extends StatefulWidget {
@override
TextFieldDemoState createState() => TextFieldDemoState();
}
class TextFieldDemoState extends State<TextFieldDemo> {
final textEditingController = TextEditingController();
@override
void dispose() {
textEditingController.dispose();
super.dispose();
}
@override
void initState() {
super.initState();
// textEditingController.text = 'hi';
textEditingController.addListener(
() {
debugPrint('input: ${textEditingController.text}');
}
);
}
@override
Widget build(BuildContext context) {
return TextField(
controller: textEditingController,
// onChanged: (value) {
// debugPrint('input: $value');
// },
onSubmitted: (value) {
debugPrint('submit: $value');
},
decoration: InputDecoration(
icon: Icon(Icons.subject),
labelText: 'Title',
hintText: 'Enter the post title.',
// border: InputBorder.none,
// border: OutlineInputBorder(),
filled: true,
),
);
}
}
class ThemeDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
color: Theme.of(context).accentColor,
);
}
}
效果:

flutter Form表单的更多相关文章
- Flutter Form表单控件超全总结
注意:无特殊说明,Flutter版本及Dart版本如下: Flutter版本: 1.12.13+hotfix.5 Dart版本: 2.7.0 Form.FormField.TextFormField是 ...
- form表单验证-Javascript
Form表单验证: js基础考试内容,form表单验证,正则表达式,blur事件,自动获取数组,以及css布局样式,动态清除等.完整代码如下: <!DOCTYPE html PUBLIC &qu ...
- Form 表单提交参数
今天因为要额外提交参数数组性的参数给form传到后台而苦恼了半天,结果发现,只需要在form表单对应的字段html空间中定义name = 后台参数名 的属性就ok了. 后台本来是只有模型参数的,但是后 ...
- form表单 ----在路上(15)
form 表单就是将用户的信息提交到服务器,服务器会将信息存储活着根据信息查询数据进行增删改查,再将其返回给用户. 基本格式: <form action="" method ...
- form表单的字符串进行utf-8编码
<form>表单有assept-charset属性.该属性规定字符的编码方式,默认是"unknown",与文档的字符集相同. 该属性除了Internet explore ...
- 细说 Form (表单)
细说 Form (表单) Form(表单)对于每个WEB开发人员来说,应该是再熟悉不过的东西了,可它却是页面与WEB服务器交互过程中最重要的信息来源. 虽然Asp.net WebForms框架为了帮助 ...
- 通过form表单的形式下载文件。
在项目中遇到问题,要求动态拼接uri下载文件.但是由于项目的安全拦截导致window.location.href 和 window.open等新建窗口的方法都不行. 无意间百度到了通过form表单来下 ...
- form 表单跨域提交
<!DOCTYPE html><html> <head> <title>form 表单上传文件</title> <script src ...
- form表单的属性标签
form表单的常用标签 表单: <form id="" name="" method="post/get" action=" ...
随机推荐
- 思想家:潘石屹学python
1.python在一些算法,图像处理,机器视觉方面越来越重要 2.计算机语言像英语一样,渐渐成为一种非专业技术,不能成为专业,而只能成为一种工具 3.想发挥工具价值,需要与别的专业结合,例如潘总的房地 ...
- 第三天Beta冲刺
团队作业Beta冲刺 项目 内容 这个作业属于哪个课程 任课教师博客主页链接 这个作业的要求在哪里 作业链接地址 团队名称 你们都是魔鬼吗 作业学习目标 (1)掌握软件黑盒测试技术:(2)学会编制软件 ...
- 帝国CMS熊掌号数据主动推送插件【原创】
因为昨晚一个朋友他是帝国CMS做的网站,叫我给他做个熊掌号改造和熊掌号推送,所以花了一个小时时间做了这个插件,有需要的朋友可以拿去. 第一步:在后台执行以下数据库语句: CREATE TABLE `b ...
- Mybatis 使用PageHelper封装通用Dao分页方法
参考: PageHelper官网:https://pagehelper.github.io/docs/howtouse/#3-%E5%A6%82%E4%BD%95%E5%9C%A8%E4%BB%A3% ...
- stm32的hal之串口库函数总结复习
1.串口的使用方法 在hal库中,有三个串口发送的函数 a.HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uin ...
- 微信支付(APP支付)-服务端开发(二 )
如果你已经可以微信支付成功,那么你已经成功90%,剩下的就是订单确认问题了. 接上一篇文章,今天我们来谈一谈,订单查询与确认: APP端支付成功之后,会再次向服务端发起请求,确认付款订单时候成功,同时 ...
- Java - Annotation使用
本文转载于(这个写的很好):https://www.cnblogs.com/be-forward-to-help-others/p/6846821.html Annotation Annotation ...
- CF446C DZY Loves Fibonacci Numbers 线段树 + 数学
有两个性质需要知道: $1.$ 对于任意的 $f[i]=f[i-1]+f[i-2]$ 的数列,都有 $f[i]=fib[i-2]\times f[1]+fib[i-1]\times f[2]$ 其中 ...
- C语言for 循环 9*9 实现九九乘法表
#include <stdio.h> int main(void) { //for循环实现9*9乘法表 /* 1*1=1 1*2=2 2*2=4 1*3=3 2*3=6 3*3=9 */ ...
- CF Gym 102028G Shortest Paths on Random Forests
CF Gym 102028G Shortest Paths on Random Forests 抄题解×1 蒯板子真jir舒服. 构造生成函数,\(F(n)\)表示\(n\)个点的森林数量(本题都用E ...