I am newbie in flutter so please let me know if i am wrong.In my application i have to logged in using facebook so i took a RawMaterialButton
and in onPressed
function in used following code
child: RawMaterialButton(
onPressed: () {
FutureBuilder<String>(
future:
_login(), // function where you call your api
builder: (BuildContext context,
AsyncSnapshot<String> snapshot) {
// AsyncSnapshot<Your object type>
print(snapshot);
if (snapshot.connectionState ==
ConnectionState.done) {
print('${snapshot.data}');
}
if (snapshot.connectionState ==
ConnectionState.waiting) {
return Center(
child: Text('Please wait its loading...'));
} else {
if (snapshot.hasError)
return Center(
child: Text('Error: ${snapshot.error}'));
else
return Center(
child: new Text(
'${snapshot.data}')); // snapshot.data :- get your object which is pass from your downloadData() function
}
},
);
return CircularProgressIndicator();
},
when i press the button its calling the method and i am getting data but after getting those data future building is not updating or showing that data in a Text
.here is my data fetch method.
Future<String> _login() async {
final result = await FacebookAuth.instance.login();
var tokenString;
switch (result.status) {
case FacebookAuthLoginResponse.ok:
_printCredentials(result);
// get the user data
// final userData = await FacebookAuth.instance.getUserData();
tokenString = result.accessToken.token;
break;
case FacebookAuthLoginResponse.cancelled:
print("login cancelled");
tokenString = "User cancelled";
break;
default:
tokenString = "Login failed";
}
return tokenString;
}
For debug purpose i made break point also but its not directing to the asynchronous snapshot
condition state checking.I could not find out the reasons. I also check following stack question also.
Why FutureBuilder doesn't get call in Flutter? Flutter FutureBuilder Not Updating