Dart error: Instance member can't be accessed using static access
Instance member 'signInWithGoogle' can't be accessed using static access.Short answer
You wrote ClassName.method() but the method belongs to an object, not to the class. Dart has two honest fixes: call it on an instance of the class, or, if the method really does not need any object state, declare it static. Pick by deciding whether the method uses fields of the object.
Fix it fast
1Find out which cause you have
Find the call and the declaration. If the call is written as AuthService.signInWithGoogle() and the declaration has no static keyword, you have a class-versus-object mix-up.
grep -rn "signInWithGoogle" lib/ dart analyze2Match what you see, then jump to its fix
What does the error look like?
Instance member 'signInWithGoogle' can't be accessed using static access.static_access_to_instance_member
Cause 1 of 2
The method should be called on an object
1Check
Open the method. If it reads this-level state, it cannot exist without an instance.
grep -n -B2 -A12 "signInWithGoogle" lib/services/auth_service.dart2Fix
Create an instance, or take one from your state management or dependency injection, and call the method on it.
final auth = AuthService();
await auth.signInWithGoogle();3Verify
The analyzer error should disappear.
dart analyzeConfirmed by dart.dev
Cause 2 of 2
The method was meant to be static
1Check
Check that no line in the method uses a non-static field.
dart analyze2Fix
Add the static keyword to the declaration. Any field it touches must then be static as well.
class AuthService {
static Future<void> signInWithGoogle() async {
// no instance fields used here
}
}3Verify
Run the analyzer again.
dart analyzeConfirmed by dart.dev
How do I stop it coming back?
- Make helper methods static only when they truly need no state.
- Run dart analyze (or flutter analyze) in CI so this error is stopped before merge.
- Pass services through constructors or a provider rather than calling them through the class name.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- Qist BazaarA buy-now-pay-later marketplace built from a blank repo, now past 100K downloads on Google Play.
- SessionBirdAn omnichannel engagement suite in Flutter: campaigns, chatbot, tickets, analytics and live calling.
Related fixes
Mobile apps
AudioCache has no play method after updating audioplayers
The method 'play' isn't defined for the type 'AudioCache'.
Since audioplayers 1.0, AudioCache only turns asset files into local files and caches them.
2 causes, each with a fixMobile apps
Flutter Bloc throws that emit was called after the event handler completed
emit was called after an event handler completed normally.
Each on<Event> handler gets its own Emitter, and it stops working the moment the handler's returned Future completes.
2 causes, each with a fixMobile apps
analysis_options.yaml: the URI it includes can't be found
include_file_not_found
The analyzer reports include_file_not_found when the file named after include: in analysis_options.yaml does not resolve.
2 causes, each with a fixMobile apps
Dart error: the body might complete normally and return null for a non-nullable type
body_might_complete_normally
Dart found a path through your function or callback that reaches the closing brace without a return.
3 causes, each with a fixMobile apps
Dart throws ConcurrentModificationError while looping over a list
ConcurrentModificationError
Dart throws this when a collection changes size while something iterates it.
2 causes, each with a fixMobile apps
Dart cannot turn a compact timestamp like 20201101153000 into a DateTime
FormatException: Invalid date format
DateTime.parse accepts a subset of ISO 8601, and a time part must be introduced by T or a space.
2 causes, each with a fix