24Flutter中常见的表单有TextField单行文本框,TextField多行文本框、CheckBox、Radio、Switch
import 'package:flutter/material.dart'; class TextFieldDemoPage extends StatefulWidget {
TextFieldDemoPage({Key key}) : super(key: key); _TextFieldDemoPageState createState() => _TextFieldDemoPageState();
} class _TextFieldDemoPageState extends State<TextFieldDemoPage> {
var _username=new TextEditingController(); //初始化的时候,给表单赋值:
var _password;
@override
void initState(){
super.initState();
_username.text="初始值";
} @override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('表单演示页面'),
),
body: Padding(
padding: EdgeInsets.all(),
child: Column(
children: <Widget>[
// TextField(),
// SizedBox(height: 20),
// TextField(
// decoration: InputDecoration(
// hintText: "请输入搜索的内容",
// border: OutlineInputBorder()
// ),
// ),
// SizedBox(height: 20),
// TextField( //设置为多行文本框:
// maxLines: 4,
// decoration: InputDecoration(
// hintText: "多行文本框",
// border: OutlineInputBorder()
// ),
// ),
// SizedBox(height: 20),
// TextField(
// obscureText: true, //把文本框修改成密码框:
// decoration: InputDecoration(
// hintText: "密码框",
// border: OutlineInputBorder()
// ),
// ),
// SizedBox(height: 20),
// TextField(
// obscureText: true,
// decoration: InputDecoration(
// hintText: "labelText使用",
// border: OutlineInputBorder(),
// labelText: "用户名"
// ),
// ),
TextDemo(),
TextField(
obscureText: true,
decoration: InputDecoration(
hintText: "labelText使用",
border: OutlineInputBorder(),
labelText: "密码"),
onChanged: (value){
setState(() {
this._password=value;
});
},
),
TextField(
decoration:
InputDecoration(icon: Icon(Icons.search), hintText: "请输入用户名"),
controller: _username,
onChanged: (value){
setState(() {
_username.text=value;
});
},
),
Container(
width: double.infinity,
height: ,
child: RaisedButton(
child: Text("登录"),
onPressed: (){
print(this._username.text);
print(this._password);
},
color: Colors.blue,
textColor: Colors.white,
),
)
],
),
),
);
}
} class TextDemo extends StatelessWidget {
const TextDemo({Key key}) : super(key: key); @override
Widget build(BuildContext context) {
return Container(
child: TextField(
decoration:
InputDecoration(icon: Icon(Icons.people), hintText: "请输入用户名"),
),
);
}
}
CheckBox.dart
import 'package:flutter/material.dart';
class CheckBoxDemoPage extends StatefulWidget {
CheckBoxDemoPage({Key key}) : super(key: key); _CheckBoxDemoPageState createState() => _CheckBoxDemoPageState();
}
// CheckBox
class _CheckBoxDemoPageState extends State<CheckBoxDemoPage> {
var flag=true;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar:AppBar(
title: Text('CheckBox'),
),
body:Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Row(
children: <Widget>[
Checkbox(
value: this.flag,
onChanged: (v){
setState(() {
this.flag=v;
});
},
activeColor: Colors.red, )
],
),
Row(
children: <Widget>[
Text(this.flag?'选中':'未选中')
],
),
SizedBox(height: ),
CheckboxListTile(
value: this.flag,
onChanged: (v){
setState(() {
this.flag=v;
});
},
title: Text('标题'),
subtitle: Text('这是一个二级标题'),
secondary: Icon(Icons.help),
)
],
)
);
}
}
24Flutter中常见的表单有TextField单行文本框,TextField多行文本框、CheckBox、Radio、Switch的更多相关文章
- javascript中常见的表单验证项
1.不能超过20个字符 <body> <form name=a onsubmit="return test()"> <textarea name=&q ...
- 在Tomcat中采用基于表单的安全验证
.概述 (1)基于表单的验证 基于From的安全认证可以通过TomcatServer对Form表单中所提供的数据进行验证,基于表单的验证使系统开发者可以自定义用户的登陆页面和报错页面.这种验证方法 ...
- Javascript中的Form表单知识点总结
Javascript中的Form表单知识点总结 在HTML中,表单是由form元素来表示的,但是在javascript中,表单则由HTMLFormElement类型,此元素继承了HTMLElement ...
- php中如何防止表单的重复提交
在php中如何防止表单的重复提交?其实也有几种解决方法. 下面小编就为大家介绍一下吧.需要的朋友可以过来参考下 代码: <?php /* * php中如何防止表单的重复提交 * by www.j ...
- javascript中的常用表单事件用法
下面介绍几种javascript中常用的表单事件: 一,onsubmit:表单中的确认按钮被点击时发生的事件,如下案例. 案例解析:弹出表单中提交的内容 <form name="tes ...
- jquery.form插件中动态修改表单数据
jquery.form jquery.form插件(http://malsup.com/jquery/form/)是大家经常会用到的一个jQuery插件,它可以很方便将表单转换为ajax的方式进行提交 ...
- 如何在.Net Core MVC中为动态表单开启客户端验证
非Core中的请参照: MVC的验证 jquery.validate.unobtrusive mvc验证jquery.unobtrusive-ajax 参照向动态表单增加验证 页面引入相关JS: &l ...
- Vue.js + Nuxt.js 项目中使用 Vee-validate 表单校验
vee-validate 是为 Vue.js 量身打造的表单校验框架,允许您校验输入的内容并显示对应的错误提示信息.它内置了很多常见的校验规则,可以组合使用多种校验规则,大部分场景只需要配置就能实现开 ...
- php中的form表单
表单处理 表单的概念在生活中很常见,就像是问卷调查表一样,别人先把问卷发给你,你照着问卷的要求填写,完事过后再将填完的问卷发给别人,从而达到一个将别人需要的信息传递给别人的一种方式. 传统的网页大多数 ...
随机推荐
- 跨域访问支持(Spring Boot、Nginx、浏览器)
原文:http://www.itmuch.com/work/cors/ 最近家中事多,好久没有写点啥了.一时间竟然不知从何说起.先说下最近家里发生的事情吧: 老爸肺气肿住院: 老妈甲状腺囊肿 儿子喘息 ...
- 运输层7——TCP的流量控制和拥塞控制
目录 1. TCP的流量控制 2. TCP的拥塞控制 写在前面:本文章是针对<计算机网络第七版>的学习笔记 运输层1--运输层协议概述 运输层2--用户数据报协议UDP 运输层3--传输控 ...
- 前端学习笔记--Visual Studio Code安装及中文显示
1.在官网https://code.visualstudio.com/下载对应的版本: 2.安装 一路点击下一步,选中 添加到PATH后,安装. 安装成功,可以直接打开使用: 把界面改成中文显示: ...
- mysql - InnoDB存储引擎 死锁问题( Deadlock found when trying to get lock; try restarting transaction )
刚刚向数据库插入数据的时候出现了这么一段错误 Deadlock found when trying to get lock; try restarting transaction 主要原因(由于无法使 ...
- 002_软件安装之_keil4与keil5共存
目的:实现keil4和keil5的共存 1. Keil4 主要用来开发 C51 程序 2. Keil5 也就是 MDK 主要用来开发 ARM 芯片,如 STM32 系列芯片 3. 资料下载地址:链接: ...
- 获取Druid连接池里当前连接数
JdbcTemplate jdbcTemplate=(JdbcTemplate) SpringUtils.getBean("jdbcMysqlTemplate"); DruidDa ...
- MySQL高级 之 explain执行计划详解(转)
使用explain关键字可以模拟优化器执行SQL查询语句,从而知道MySQL是如何处理你的SQL语句的,分析你的查询语句或是表结构的性能瓶颈. explain执行计划包含的信息 其中最重要的字段为:i ...
- 013_Python3 条件控制
1.if #!/usr/bin/python3 var1 = 100 if var1: print ("1 - if 表达式条件为 true") print ( ...
- Cogs 731. [网络流24题] 最长递增子序列(最大流)
[网络流24题] 最长递增子序列 ★★★☆ 输入文件:alis.in 输出文件:alis.out 简单对比 时间限制:1 s 内存限制:128 MB «问题描述: 给定正整数序列x1,-, xn. ( ...
- Codevs 4927 线段树练习5(分块)
4927 线段树练习5 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 有n个数和5种操作 add a b c:把区间[a,b]内的 ...