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=" ...
随机推荐
- wireshark 抓包再利用TCP socket发送包里的payload是可以实现登陆的
用户密码可被批量破解 在用户使用手机端登录时,对数据进行抓包分析. 多次抓包分析后,可得到几个关键TCP数据包. 根据前面逆向编写出的解密算法,使用socket进行数据发包测试: 可以模拟APK进行用 ...
- :Spring-06 -AOP [面向切面编程] -配置异常通知的两种方式--AspectJ 方式 -Schema-based 方式
三.配置异常通知的步骤(AspectJ 方式) 1.只有当切点报异常才能触发异常通知 2.在spring 中有AspectJ 方式提供了异常通知的办法 3.实现步骤: 3.1新建类,在类写任意名称的方 ...
- BOM常用属性与方法
BOMBrowser Object Modelwindow浏览器窗口window方法locationlocation常用属性screen显示器屏幕screen常用属性navigator浏览器软件nav ...
- RSA 加密 解密 (长字符串) JAVA JS版本加解密
系统与系统的数据交互中,有些敏感数据是不能直接明文传输的,所以在发送数据之前要进行加密,在接收到数据时进行解密处理:然而由于系统与系统之间的开发语言不同. 本次需求是生成二维码是通过java生成,由p ...
- destoon模板语法规则笔记
1.包含模板 {template 'header'} 或 {template 'header', 'member'} {template 'header'} 被解析为 : <?php inclu ...
- Eclipse中安装Spring IDE
====>在线安装 1.寻找Spring IDE插件更新地址:http://marketplace.eclipse.org/content/spring-ide 2.复制对应Eclipse版本的 ...
- PostgreSQL 抛出错误信息(错误行号)
抛出错误行号是我们在写SQL中常用到的,在SQL Server和Oracle中都很简单,但是在PostgreSQL怎么实现呢?在网上查了下资料只有pg_exception_context包含错误行,我 ...
- Linux rpm安装指定安装路径
可以使用prefix参数. rpm -i –prefix=/home/gpadmin greenplum-db-6.0.0-rhel6-x86_64.rpm 将greenplum-db-6.0. ...
- QGraphicsView,QGraphicsScene,QGraphicsItem
参考:Qt4 开发实践第八章 图形视图QGraphicsView #ifndef DRIVEDGRAPH_H #define DRIVEDGRAPH_H #include <QObject> ...
- POJ 2987 Firing 最大流 网络流 dinic 模板
https://www.cnblogs.com/137shoebills/p/9100790.html http://poj.org/problem?id=2987 之前写过这道题,码一个dinic的 ...