可能是一个非常具体的边缘案例,但我注意到我的web应用程序无法通过web浏览器在某些移动设备上运行。该代码在本地移动应用程序和桌面浏览器上运行良好,但某些移动浏览器无法正常工作。
通常情况下,当有人试图登录时,会打开一个弹出窗口,用户要么选择自己的帐户,要么默默登录,但我从某些移动设备上注意到,弹出/登录过程从未发生过。有没有办法强制Flutter网络应用程序通过重定向而不是弹出窗口打开谷歌登录?或者可能是我不知道的其他解决方案?
这是我正在使用的代码:
Widget _googleSignInButton() {
return FlatButton(
minWidth: 300,
color: Colors.white60,
onPressed: () async {
setState(() {
isLoading = true;
});
await signInWithGoogle().then((user) {
if (user != null) {
Navigator.of(context).pop();
Navigator.pushNamed(context, DashboardRoute);
}
}).catchError((onError) {
setState(() {
isLoading = false;
});
});
},...
Future<String> signInWithGoogle() async {
final GoogleSignInAccount googleSignInAccount = await googleSignIn.signIn();
final GoogleSignInAuthentication googleSignInAuthentication =
await googleSignInAccount.authentication;
final AuthCredential credential = GoogleAuthProvider.credential(
accessToken: googleSignInAuthentication.accessToken,
idToken: googleSignInAuthentication.idToken,
);
final UserCredential authResult =
await _auth.signInWithCredential(credential);
final User user = authResult.user;
// Checking if email and name is null
assert(user.email != null);
assert(user.displayName != null);
assert(user.photoURL != null);
userID = user.uid;
newUser = authResult.additionalUserInfo.isNewUser;
if (newUser) {
userData['name'] = user.displayName;
userData['email'] = user.email;
userData['photo'] = 'assets/images/userIcon.png';
await createUser();
} else {
await getUserData();
}
assert(!user.isAnonymous);
assert(await user.getIdToken() != null);
final User currentUser = _auth.currentUser;
assert(user.uid == currentUser.uid);
return 'signInWithGoogle succeeded: $user';
}
问题来自于第三方cookie被禁用,这会阻止.signin((方法打开新窗口。这抛出了一个PlatformException,据我所知,它不能被飞镖捕获