我是 Flutter 的新手。我有Firebase Auth/Google Auth 的问题FirebaseUser未定义代码:
FirebaseAuth _auth = FirebaseAuth.instance;
GoogleSignIn googleSignIn = GoogleSignIn();
Future<FirebaseUser> currentUser() async { // The Issue is here in the Future<>
final GoogleSignInAccount account = await googleSignIn.signIn();
final GoogleSignInAuthentication authentication =
await account.authentication;
final GoogleAuthCredential credential = GoogleAuthProvider.getCredential(
idToken: authentication.idToken, accessToken: authentication.accessToken);
final AuthResult authResult = await _auth.signInWithCredential(credential);
final FirebaseUser user = authResult.user; // and here as I can't define this FirebaseUser object to return
return user;
}
Run Code Online (Sandbox Code Playgroud)
pubspec.yml
dependencies:
flutter:
sdk: …Run Code Online (Sandbox Code Playgroud) google-authentication dart firebase firebase-authentication flutter
I'm trying to add WidgetsBindingObserver accoidring to (https://medium.com/@phongyewtong/best-method-to-restart-reload-your-flutter-app-on-startup-2f787cecc6d6)
class MyApp extends StatefulWidget with WidgetsBindingObserver {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this); // The Error is right here
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialHomeApp();
}
Run Code Online (Sandbox Code Playgroud)
The Erros says The argument type '_MyAppState' can't be assigned to the parameter type 'WidgetsBindingObserver'.dartargument_type_not_assignable