Flutter:无法使用静态访问权限访问实例成员'signInWithGoogle'. (位于的"static_access_to_instance_member") [英] Flutter: Instance member 'signInWithGoogle' can't be accessed using static access. (static_access_to_instance_member at )
问题描述
我尝试为Flutter项目做绒毛,我有一个用于登录和注销Google帐户的类API,Linter希望在使用这些方法(使用Google登录并注销)之前先删除static.我无法在视图中调用这些函数.这是我的代码:
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错误
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
Logout.dart
Future<void> _signOut() async {
try {
await FBApi.signOut();
} catch (e) {
print(e);
}
}
推荐答案
await FBApi.signInWithGoogle();---> error
应该是
await FBApi().signInWithGoogle();
您首先需要创建一个实例()
来调用实例方法.
You first need to create an instance ()
to call an instance method.
或者,您可以更改
Future<FBApi> signInWithGoogle() async {
到
static Future<FBApi> signInWithGoogle() async {
在不首先创建实例的情况下使signInWithGoogle
可用.
to make signInWithGoogle
available without creating an instance first.
我不知道意图是什么.
这篇关于Flutter:无法使用静态访问权限访问实例成员'signInWithGoogle'. (位于的"static_access_to_instance_member")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!