본문 바로가기
프레임워크/flutter

[Error]Instance member can't be accessed using static access.

by seongjko 2023. 11. 25.
728x90

문제:

ApiService의 getTodaysToons method를 다른 클래스에서 호출하려 했더니 제목의 에러가 발생함.

 

해결 과정:

stackoverflow에 검색해보니 인스턴스 메서드를 만들기 위해서는 일단 인스턴스를 호출해야 한다고 함.

https://stackoverflow.com/questions/54413029/flutter-instance-member-signinwithgoogle-cant-be-accessed-using-static-acces

 

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 t...

stackoverflow.com

 

 

인스턴스를 호출하는 방법은 ApiService 뒤에 ()를 붙여주면 됨.

처리해주면 이렇게 에러가 사라진 모습을 볼 수 있음

 

에러 발생 원인:

ApiService 클래스 안에 있는 모든 변수와 메서드에 static & const 처리를 해주지 않아서 발생한 에러.

아래와 같이 수정했더니 ApiService 뒤에 '()'을 붙이지 않아도 에러가 발생하지 않았다. 

반응형