使用Google登录时,在我进入userInfoPath之前,屏幕变黑,然后再次显示登录页面,然后再移至userInfoPath。我正在尝试添加加载小部件,以便它可以很好地从Google登录名过渡到userInfoPath,但是我可以获取加载小部件,并且将其保留在其上而无需移至UserInfoScreen或根本无法获得它。有关如何解决此问题的帮助将非常有用。
登入画面
class LoginScreen extends StatefulWidget {
@override
_LoginScreenState createState() => _LoginScreenState();
}
class _LoginScreenState extends State<LoginScreen> {
AuthService auth = AuthService();
@override
void initState() {
super.initState();
auth.getUser.then(
(user) {
if (user != null) {
Navigator.pushReplacementNamed(context, SharedStrings.userInfoPath);
}
},
);
}
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
backgroundColor: white,
body: Container(
padding: Sizes2.edInsAll,
decoration: const BoxDecoration(),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Image.asset(Strings.imageLogo,
width: Sizes2.imageWidth,
height: Sizes2.imageHeight,
),
Text(SharedStrings.planetRescue, style: appName, textAlign: TextAlign.center),
Text(Strings.liveSustainablySlogan, style: greySubTxt, textAlign: TextAlign.center),
LoginButton(
text: Strings.loginWithGoogle,
icon: FontAwesomeIcons.google,
color: orangeGrey,
loginMethod: auth.googleSignIn,
),
Container(
margin: Sizes1.onlyBot,
child: FlatButton.icon(
padding: Sizes2.edInsAll,
icon: const Icon(Icons.email, color: Colors.white),
color: orangeGrey,
onPressed: () => changeScreen(context, AuthWidget()),
label: Expanded(
child: Text(Strings.loginWithEmail, style: formalBtnTextSml, textAlign: TextAlign.center),
),
),
),
...
登录按钮
class LoginButton extends StatelessWidget {
final Color color;
final IconData icon;
final String text;
final Function loginMethod;
const LoginButton({Key key, this.text, this.icon, this.color, this.loginMethod}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
margin: Sizes1.onlyBot,
child: FlatButton.icon(
padding: Sizes1.edgInAll,
icon: Icon(icon, color: Colors.white),
color: color,
onPressed: () async {
var user = await loginMethod();
if (user != null) {
Navigator.pushReplacementNamed(context, SharedStrings.userInfoPath);
}
...
加载小部件
class Loading extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
color: white,
child: Center(
child: SpinKitChasingDots(
color: deepOrange,
size: Sizes2.loadSz,
),
),
);
}
}
首先创建以下两种方法:
void showDialogue(BuildContext context){
showDialog(
context: context,
builder: (BuildContext context) => Loading(),
);
}
void hideProgressDialogue(BuildContext context) {
Navigator.of(context).pop(Loading());}
然后在中LoginButton
,替换为:
onPressed: () async {
var user = await loginMethod();
if (user != null) {
Navigator.pushReplacementNamed(context, SharedStrings.userInfoPath);
}
带有:
onPressed: () async {
showDialogue(context);
var user = await loginMethod();
if (user != null) {
hideProgressDialogue(context);
Navigator.pushReplacementNamed(context, SharedStrings.userInfoPath);
}
让我知道这是否对您有用:)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句