没掌握的点:
enabled: false,//这个属性可以禁用TextField
onSubmitted onEdittingComplete都是在按下Enter键之后调用的函数;
decoration: InputDecoration(
prefixIcon: Icon(Icons.local_airport),//输入框内的图标
hintText: 'Input Here',//输入框提示文字
filled: true,//输入框颜色铺满,
fillColor: Colors.white70,//输入框颜色选择
contentPadding: EdgeInsets.all(10),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(15),
),
),
下面是完整示例:
import 'package:flutter/material.dart';
void main()=>runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
TextEditingController _userNameController=TextEditingController();
TextEditingController _passWordController=TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: <Widget>[
TextField(
controller: _userNameController,
decoration: InputDecoration(
icon: Icon(Icons.desktop_windows),
labelText: '输入你的号码',
hintText: '输入你的手机号码',
),
),
TextField(
controller: _passWordController,
decoration: InputDecoration(
icon: Icon(Icons.perm_camera_mic),
labelText: '输入你的密码',
hintText: '你的密码安全么',
),
),
RaisedButton(
onPressed:(){
logOn();
},
child: Text('操你大爷的'),
),
],
),
);
}
void onTextClear() {
setState(() {
_userNameController.clear();
_passWordController.clear();
});
}
logOn(){
if(_userNameController.text.length!=11){
showDialog(
context: context,
builder: (context)=>AlertDialog(
title: Text('请输入正确的电话号码'),
),
);
}else if(_passWordController.text.length!=6){
showDialog(
context: context,
builder: (context)=>AlertDialog(
title: Text('请输入正确的密码'),
),
);
}else{
showDialog(
context: context,
builder: (context)=>AlertDialog(
title: Text('登陆成功'),
),
);
onTextClear();
}
}
}