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=" ...
随机推荐
- Bias vs. Variance(1)--diagnosing bias vs. variance
我们的函数是有high bias problem(underfitting problem)还是 high variance problem(overfitting problem),区分它们很得要, ...
- 动态加载 ShellCode绕过杀软
反病毒解决方案用于检测恶意文件,并且通常使用静态分析技术来区分二进制文件的好坏.如果是恶意文件本身包含恶意内容(ShellCode),那么依靠静态分析技术会非常有效,但如果攻击者使用轻量级的stage ...
- Hdfs读写数据出错
1.Hdfs读数据出错:若在读数据的过程中,客户端和DataNode的通信出现错误,则会尝试连接下一个 包含次文件块的DataNode.同时记录失败的DataNode,此后不再被连接. 2.Hdfs在 ...
- [TypeScript] Modifier
TypeScript 2.8 adds the ability for a mapped type to either add or remove a particular modifier. Spe ...
- Apache Solr Velocity模板远程代码执行
更多内容,欢迎关注微信公众号:信Yang安全,期待与您相遇. 这里用的docker环境 很简单的 在这里不再介绍 本地搭建好环境然后访问8983端口 网页如下: 查下节点名称 同样名字可以访问http ...
- Windows下 Python 2 与 Python 3 共存
转自:http://lovenight.github.io/2016/09/27/Windows%E4%B8%8B-Python-2-%E4%B8%8E-Python-3-%E5%85%B1%E5%A ...
- (10)打鸡儿教你Vue.js
事件处理器 <div id="app"> <button v-on:click="counter += 1">增加 1</butt ...
- 一次 react-router 中遇到的小坑
react-router Link 标签不生效的问题 废话不多说, 直接上问题, 排解过程和答案 现象: 发现 使用 Link 标签没有 元素的样式和效果, 也不能进行跳转 代码如下: render( ...
- Xshell6如何传输文件
Xshell6如何传输文件 /或者直接在本地用notepad nftp插件上传本地文件,直观,更方便 上传文件 1.打开xshell6软件,连接服务器. 2.yum安装一款工具.#yum inst ...
- Tkinter 之ProgressBar进度条标签
一.参数说明 参数 作用 cursor 鼠标位于进度条内时的形状 length 进度条长度 maximum 进度条最大刻度值 mode 进度条的模式.有两种:‘determinate’和’indet ...