flutterTextField使⽤⽅法import 'package:flutter/material.dart';
/*
*flutter TextField组件详解
*/
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'TextField ',
home: Scaffold(
appBar: AppBar(
title: Text("TextField组件"),
),
body: TextFieldDemo(),
),
);
}
}
class TextFieldDemo extends StatefulWidget {
@override
_TextFieldDemoState createState() => _TextFieldDemoState();
}
class _TextFieldDemoState extends State<TextFieldDemo> {
var _username = new TextEditingController(); //⽤来初始化给表单赋值
var _password; //默认没有初始值
@override
void initState() {
super.initState();
_ = '⽤户名';
}
@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.all(20),
child: Column(children: [
//最简单的textField
textstyleTextField(),
SizedBox(height: 20),
//有边框的textField
TextField(
decoration: InputDecoration(
hintText: '有边框的textField', border: OutlineInputBorder()),
),
SizedBox(height: 20),
//多⾏⽂本框的TextField
TextField(
maxLines: 4,
decoration: InputDecoration(
hintText: '多⾏⽂本框的TextField', border: OutlineInputBorder()),
),
SizedBox(height: 20),
//密码框的TextField
TextField(
obscureText: true,
decoration: InputDecoration(
hintText: '密码框的TextField', border: OutlineInputBorder()),
),
SizedBox(height: 20),
//⽂本浮在左上⾓的TextField

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。