Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Dart error: Instance member can't be accessed using static access

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

  • Applies to Dart 3.9, Flutter 3.35
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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 analyze
  2. 2Match what you see, then jump to its fix

    1. 1The method uses fields or other instance members of its class (a FirebaseAuth instance, a stored user).The method should be called on an objectFix
    2. 2The method needs nothing from the object and you want to call it as AuthService.signInWithGoogle().The method was meant to be staticFix

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

2Fix

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 analyze

Confirmed by dart.dev

Did this fix it?

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 analyze

2Fix

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 analyze

Confirmed by dart.dev

Did this fix it?

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:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.