firebase - Flutter: Instance member 'signInWithGoogle' can't be accessed using static access. (static_access_to_instance_member at )
问题描述
I try to lint for my Flutter project, I have a class API to log in and log out google account, Linter prefers to remove static before these methods (login with Google and sign out). I cannot call these functions in view. Here my code:
API.dart
class FBApi {
FBApi(this.firebaseUser);
...
Future<FBApi> signInWithGoogle() async {
final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
final GoogleSignInAuthentication googleAuth =
await googleUser.authentication;
...
}
Future<void> signOut() async {
await _auth.signOut().then((_) {
print('***** log out...what the hell?');
_googleSignIn.disconnect();
_googleSignIn.signOut();
// Navigator.of(context).pushNamedAndRemoveUntil("/login", ModalRoute.withName("/home"));
});
}
}
Login.dart error above
Future<bool> _loginUser() async {
final FBApi api = await FBApi.signInWithGoogle();---> error
if (api != null) {
return true;
} else {
return false;
}
}
Logout.dart
Future<void> _signOut() async {
try {
await FBApi.signOut();
} catch (e) {
print(e);
}
}
解决方案
await FBApi.signInWithGoogle();---> error
应该
await FBApi().signInWithGoogle();
您首先需要创建一个实例()
来调用实例方法。
或者,您可以更改
Future<FBApi> signInWithGoogle() async {
至
static Future<FBApi> signInWithGoogle() async {
signInWithGoogle
在不首先创建实例的情况下使其可用。
我不知道真正的意图是什么。
推荐阅读
- sql - 将表中的每一行与其他每一行进行比较,一次且仅一次
- sql - 使用 postgresql 计算 datediff 并产生年数
- odoo - 如何在 Odoo 中定义自定义设置
- git - 如何解决致命:无法访问,CONNECT 后从代理收到 HTTP 代码 400
- mysql - 如何使用用户提交的变量进行查询并保存?
- ios - 从 UITabBarController 模态显示 ViewController 而不隐藏标签栏
- python - 如何使用 Python 从 shell 连接 MySQL 工作台?
- r - 如何创建对用户输入做出反应的反应数据框_
- java - 如何在 Java 中打开带有锚点的 URL?
- python - 如何在 Python 中从 Azure Databricks 插入 Azure SQL 数据库