在我使用 Facebook SignIn 登录后的颤振应用程序中,如果登录成功但如果取消或出现错误,我希望用户转到下一个屏幕,显示带有详细信息的小吃栏。如果登录成功,我已经设法将用户移动到下一个屏幕,但我无法显示小吃栏。
这是我的代码:
class LoginScreen extends StatefulWidget {
static const routeName = 'login_screen';
@override
_LoginScreenState createState() => _LoginScreenState();
}
class _LoginScreenState extends State<LoginScreen> {
final _key = GlobalKey<ScaffoldState>();
final FacebookAppSignIn facebookAppSignIn = FacebookAppSignIn();
@override
Widget build(BuildContext context) {
ScreenData().init(context);
return Scaffold(
key: _key,
extendBodyBehindAppBar: true,
body: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
height: ScreenData.screenHeight,
// width: ScreenData.screenWidth,
color: Colors.grey,
child: Stack(
fit: StackFit.expand,
children: <Widget>[
// Facebook login button
Button.signInOption(
onPressed: () {
facebookAppSignIn.fbLogin().whenComplete(() {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) {
return _buildFacebook(facebookAppSignIn.fbResult.status);
},
),
);
});
},
buttonColor: AppColors.blue,
iconData: FontAwesomeIcons.facebookF,
context: context,
label: 'Sign Up With Facebook',
labelSize: 15,
labelColor: Colors.white,
borderRadius: 28),
),
],
),
),
],
),
),
);
}
showSnackbar() {
_key.currentState.showSnackBar(SnackBar(
content: Text('Please check internet connection'),
duration: Duration(seconds: 7),
));
}
_buildFacebook(FacebookLoginStatus stat) {
switch (stat) {
case FacebookLoginStatus.loggedIn:
print('_buildFacebook - user is welcome');
return LandingScreen();
case FacebookLoginStatus.cancelledByUser:
print('_buildFacebook - cancelled by user');
return LoginScreen();
case FacebookLoginStatus.error:
return LoginScreen();
break;
default: print('facebook login issue');
}
}
}
我曾考虑initState
通过检查 Facebook 登录状态的值来显示snackBar,但我意识到在第一个屏幕构建时它会为空,因此会出错。我该怎么做?