admin 管理员组文章数量: 1086019
On Flutter web, the google_sign_in package renderButton is successfully prompting me to log in with google, but when I select an account, it gets stuck on ";. My code is based on this example from the google_sign_in GitHub repository. The only error in the console says “Uncaught TypeError: Cannot read properties of null (reading "postMessage')”.
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:google_sign_in_web/web_only.dart';
import 'package:google_sign_in/google_sign_in.dart';
class LoginPage extends StatefulWidget {
const LoginPage({super.key});
@override
State<LoginPage> createState() => _LoginPageState();
}
class _LoginPageState extends State<LoginPage> {
final fireStoreInstance = FirebaseFirestore.instance;
bool isLoading = false;
String _status = "Checking login status...";
late UserCredential? tempCred;
final GoogleSignIn _gsi = GoogleSignIn(
clientId: '[MY_CLIENT_ID].apps.googleusercontent', //yes, I used the correct client ID
);
GoogleSignInAccount? _currentUser;
@override
void initState() {
_gsi.onCurrentUserChanged.listen((GoogleSignInAccount? account) async {
setState(() {
_currentUser = account;
_status = _currentUser?.email ?? "Something is null...";
});
await _gsi.requestScopes(['.birthday.read']);
});
super.initState();
//_gsi.signInSilently(); //unnecessary for now, since I'm just testing renderButton
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).primaryColor,
toolbarHeight: 50,
actions: [
IconButton(
icon: const Icon(Icons.home_max_sharp),
onPressed: () {
Navigator.pop(context);
},
),
],
),
body: Center(
child: isLoading
? Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const CircularProgressIndicator(),
const SizedBox(height: 20),
Text(_status), // Show status for debugging
],
)
: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const SizedBox(height: 20),
renderButton(
configuration: GSIButtonConfiguration(
shape: GSIButtonShape.pill,
size: GSIButtonSize.medium,
logoAlignment: GSIButtonLogoAlignment.center,
),
),
const SizedBox(height: 20),
Text(
_status,
style: const TextStyle(
fontSize: 16,
color: Colors.red,
),
),
],
),
),
);
}
}
I was expecting the Oauth process to complete, with the status text either showing the user's email or "Something is null...". The status text did not change and as mentioned, the sign in window was stuck on "accounts.google/gsi/transform" after selecting an account.
The url of my Project IDX workspace is authorized in the Firebase console, I have double checked the client ID is correct, and the url of the workspace is authorized for Oauth redirects. Any idea what I am missing here?
本文标签: dartFlutter Web googlesignin renderButton freezing log in processStack Overflow
版权声明:本文标题:dart - Flutter Web google_sign_in renderButton freezing log in process - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1744056023a2525863.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论