我正在尝试将忘记密码添加到我的登录页面
当我点击发送按钮时,发送到服务器的HTTP请求
我所做的是
我将HTTP请求放入Future函数中,并在onPressed中调用了该函数,但没有任何反应
哪里不对了 ??
我的HTTP功能
Future<Map<String, dynamic>> send (String username, String email) async{
final Map<String, dynamic> authData ={
'Username' :username,
'Password': email,
};
final http.Response response = await http.post('url',
body: json.encode(authData),
headers: {'Content-Type': 'application/json'},
);
final Map<String, dynamic> responseData = json.decode(response.body);
bool hasError = true;
String message = 'Data is not Valid';
if ( responseData["StatusCode"] == 200 ) {
print('forget password');
showDialog(context:context, builder: (BuildContext context){
return AlertDialog(
title: Text("Note!"),
content: Text('check your email'),
actions: <Widget>[
FlatButton(child: Text("OK"),
onPressed: (){
Navigator.of(context).pop();
},)
],);
});
} else if(responseData.containsKey("StatusCode") != '200') {
message='invalid username or email ';
print('error');
}
return {'success': !hasError, 'message': message};
}
和函数调用
final sendbutton = Padding(
padding: EdgeInsets.symmetric(vertical: 16.0),
child:RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24),
),
onPressed: ()=> send,
padding: EdgeInsets.all(12),
color: Colors.orangeAccent,
child: Text('Send', style: TextStyle(color: Colors.white)),
),
);
有什么问题吗?
答案 0 :(得分:0)
您应该解决调用send函数的方式
droplet ip