import 'package:flutter/material.dart';
import 'package:the_don_flutter/userModel.dart';
import 'package:validate/validate.dart';
import 'package:http/http.dart' as http;
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'signup.dart';
class Login extends StatefulWidget{
@override
State<Login> createState() {
// TODO: implement createState
return LoginFormState();
}
}
class LoginFormState extends State<Login>{
final GlobalKey<FormState> formKey = new GlobalKey<FormState>();
String _passwordValidation(String value){
if(value.isEmpty){
return "Field Can't be empty.";
}else if(value.length < 6)
return "Password must be of six characters long.";
return null;
}
String _checkValidEmail(String value){
try{
Validate.isEmail(value);
}catch(e){
return "Email is not valid.";
}
return null;
}
Future<User> _loginUser() async{
var response = await http.post("https://example/public/api/login", headers: {}, body: {'username':'poras@techaheadcorp.com', 'password':'123456'})
.catchError((error) => print("Error $error"));
print("response of login ${response.body}");
return User.fromJson(json.decode(response.body));
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
body: Container(
padding: EdgeInsets.only(left: 20.0, top: 100.0, right: 20.0),
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/bg_green.jpg"),
fit: BoxFit.fill)),
child: Column(
children: <Widget>[
Form(
key: formKey,
child: Column(children: <Widget>[
Padding(padding: EdgeInsets.only(bottom: 20.0),
child: TextFormField(
validator: _checkValidEmail,
decoration: InputDecoration(
hintText: "abc@example.com",
labelText: "User Name",
hintStyle: TextStyle(color: Colors.white)),
style: TextStyle(color: Colors.white),
autofocus: true,),),
TextFormField(
obscureText: true,
validator: _passwordValidation,
decoration: InputDecoration(
hintText: "password",
labelText: "Password",
hintStyle: TextStyle(color: Colors.white)),
style: TextStyle(color: Colors.white),
autofocus: true,)
],),),
Padding(padding: EdgeInsets.only(top: 20.0),
child: Row(mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Text("Forgot Password?", textAlign: TextAlign.start, style: TextStyle(color: Colors.white,),),
],),),
Padding(padding: EdgeInsets.only(top: 20.0),
child: GestureDetector(
onTap: _submitForm,
child: Row(mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Text("LOGIN", textAlign: TextAlign.start, style: TextStyle(color: Colors.white, fontSize: 40.0),),
Icon(Icons.chevron_right, size: 40.0, color: Colors.white,),
],),), ),
Expanded(
child: Padding(padding: EdgeInsets.only(bottom: 20.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Text("Don't have an account?", textAlign: TextAlign.start, style: TextStyle(color: Colors.white,),),
Container(
margin: EdgeInsets.only(left: 8.0),
child: GestureDetector(
onTap: (){Navigator.push(context, MaterialPageRoute(builder: (context) => Signup()));},
child: Text("REGISTER NOW!", textAlign: TextAlign.start, style: TextStyle(color: Colors.black,),),
)),
],
),))
],
),
),
);
}
_submitForm() {
if(formKey.currentState.validate()){
print("Go to Home page");
_loginUser();
}
}
}
要显示ProgressDialog
on按钮,请在API
在登录屏幕上获取数据时单击。
试试这个
声明此方法以显示进度对话框
showLoaderDialog(BuildContext context){
AlertDialog alert=AlertDialog(
content: new Row(
children: [
CircularProgressIndicator(),
Container(margin: EdgeInsets.only(left: 7),child:Text("Loading..." )),
],),
);
showDialog(barrierDismissible: false,
context:context,
builder:(BuildContext context){
return alert;
},
);
}
onPressed: () {
showLoaderDialog(context);
//api here },
Navigator.pop(context);
当我单击登录按钮时,我想显示,并且移动到另一个页面需要时间。我该怎么做?
问题内容: 我正在尝试制作一个可以帮助我评估从Web资源下载文件的时间的应用程序。我发现了2个样本: 使用Android下载文件,并在ProgressDialog中显示进度 和 http://www.helloandroid.com/tutorials/how-download-fileimage-url- 您的设备 第二个示例显示了较小的下载时间,但是我不明白如何使用它来更新进度对话框。我认为在
我试图在Web视图中加载内容时显示progressDialog。完成后,progressDialog将被取消。 我有两个测试设备Android2.3.6和Android4.0。在Android2.3.6中,完全没有问题。对于Android 4.0平板电脑,在显示进度对话框时,点击它将隐藏或删除进度对话框,并使屏幕变为空白。 我的对话有什么问题? 谢谢
问题内容: 我正在开发一个android项目,当用户下载文件时该项目显示进度对话框。 但是,当用户触摸屏幕时,进度对话框将被关闭,而无需等待100%。我已经尝试使用此: 但这不起作用。 如何避免这种情况? 更新1: 似乎setCancelable(false)可以正常工作。非常感谢您的回答,但是当持久下载并用户决定放弃下载时,这将是不可能的,因为我已经停用了back keyCode: 我该如何解决
问题内容: 我是android开发的新手。我想在我的应用程序中使用开发一个。当我单击“搜索”按钮时,应当与一起出现,表明在切换到另一个按钮之前进度一直在进行。请给我推荐示例代码。 问题答案: 使用。不过,您应该在new上进行工作,并在完成时使用a 回调到。这是我的方法:
我在谷歌上搜索了很多,甚至浏览了很多这个网站的问题,但我就是找不到解决我问题的方法。 我想创建一个像下面这样的进度对话框。但我不明白如何做到这一点。我已经尝试创建一个自定义的进度对话框,但。使用它,你只能修改内部旋转器的外观。在我的情况下,我想修改它的布局。我如何实现...???? 到目前为止,我已经尝试了以下方法...