Reputation: 567
I want to get two parameters from createUser response.
I have a raisedbutton and i want to use FutureBuilder when onPressed.
future property works well, but i can not get in builder property. I tried everything but i could not find solution.
...
RaisedButton(
elevation: 5.0,
onPressed: (){
FutureBuilder(
future: createUser(usernameController.text, emailController.text, passwordController.text, '1', 1),
builder: (context, snapshot) {
if (snapshot.hasData) {
saveLogin(snapshot.data.userUnique);
nextScreen(
context,
UserDetail(
userUnique: snapshot.data.userUnique,
));
} else {
return MyHomePage();
}
return MyHomePage();
});
},
...
Future createUser(String username, String password, String email,
String logintype, int userUnique) async {
String url =
"http://api.xx.com/api/register?username=$username&password=$password&email=$email&logintype=$logintype&userUnique=$userUnique";
final response =
await http.get(url, headers: {'Content-Type': 'application/json'});
return registerFromJson(utf8.decode(response.bodyBytes));
Upvotes: 0
Views: 294
Reputation: 567
I changed FutureBuilder to async / await method
thanks for your help @pskink
onPressed: () async {
var xx = await createUser( usernameController.text, emailController.text, passwordController.text, '1',userUnique());
print(xx.responseCode.toString());
print(xx.userUnique.toString());
saveLogin(userUnique());
},
Upvotes: 2