Skip to content

Commit

Permalink
实现注册http请求
Browse files Browse the repository at this point in the history
  • Loading branch information
GZYangKui committed Aug 11, 2018
1 parent 0b3a5cf commit cd72f29
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions lib/screens/register_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class _RegisterScreenState extends State<RegisterScreen>
with SingleTickerProviderStateMixin {
AnimationController _controller;
GlobalKey<FormState> _form = new GlobalKey();
String _userName;
String _password;
String _rePassword;
String _userName="";
String _password="";
String _rePassword="";

@override
void initState() {
Expand Down Expand Up @@ -96,14 +96,15 @@ class _RegisterScreenState extends State<RegisterScreen>
);
}
void _register() async{

HttpClient client = HttpClient();
if(_userName!=null&&_password!=null&&_rePassword!=null) {
if(_userName.trim()!=""&&_password.trim()!=""&&_rePassword.trim()!="") {
if (_password.trim() != _rePassword.trim()) {
Scaffold.of(_form.currentContext).showSnackBar(
SnackBar(content: Text("两次密码不一致!")));
return;
}
await client.postUrl(Uri.http("www.dashixiuxiu.cn","register_action")).then((request){
client.postUrl(Uri.http("www.dashixiuxiu.cn","register_action")).then((request){
Map registerMes={
"username":"$_userName",
"password":"$_password",
Expand All @@ -112,15 +113,24 @@ class _RegisterScreenState extends State<RegisterScreen>
};
request.write(json.encode(registerMes));
return request.close();

}).then((response){
response.transform(utf8.decoder).listen((result){
var res = json.decode(result);
print(res["status"]);
if(res["status"]=="success"){
Scaffold.of(_form.currentContext).showSnackBar(
SnackBar(content: Text("注册成功!")));
}else{
Scaffold.of(_form.currentContext).showSnackBar(
SnackBar(content: Text("注册失败!")));
}
});

});

}else{
Scaffold.of(_form.currentContext).showSnackBar(
SnackBar(content: Text("用户名/密码不能为空!")));
}
}

}

0 comments on commit cd72f29

Please sign in to comment.