Flutter code written for google_sign_in 6 stops compiling after the upgrade to 7
Your error
error • The class 'GoogleSignIn' doesn't have an unnamed constructor. Try using one of the named constructors defined in 'GoogleSignIn' • new_with_undefined_constructor_default3 more lines it can showFix it fast
Most common cause, 1 of 3The code creates its own GoogleSignIn object
Use GoogleSignIn.instance and call initialize at startup.
import 'package:google_sign_in/google_sign_in.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await GoogleSignIn.instance.initialize(
serverClientId: 'YOUR_WEB_CLIENT_ID.apps.googleusercontent.com',
);
runApp(const MyApp());
}Short answer
google_sign_in 7 is a rewrite. GoogleSignIn is now a singleton reached through GoogleSignIn.instance, initialize() must be called once first, signIn() became authenticate(), signInSilently() became attemptLightweightAuthentication(), and access tokens come from authorizationClient instead of authentication. Update each call, or pin ^6 until you can migrate.
Which cause do you have?
Confirm the resolved version, then list every call site. Each old call has one replacement, so the list is your migration checklist.
flutter pub deps --style=compact | grep google_sign_in
grep -rnE "GoogleSignIn\(|\.signIn\(|signInSilently|\.authentication|accessToken" libThen find the line you see in this list and open its fix:
- 1The code creates its own GoogleSignIn object
doesn't have an unnamed constructor, at a line like GoogleSignIn(scopes: [...]) - 2signIn and signInSilently were renamed and split
signIn or signInSilently isn't defined for the type 'GoogleSignIn' - 3accessToken is read from authentication
The getter 'accessToken' isn't defined for the type 'GoogleSignInAuthentication'
What does the error look like?
error • The class 'GoogleSignIn' doesn't have an unnamed constructor. Try using one of the named constructors defined in 'GoogleSignIn' • new_with_undefined_constructor_defaulterror • The method 'signIn' isn't defined for the type 'GoogleSignIn'.error • The method 'signInSilently' isn't defined for the type 'GoogleSignIn'.error • The getter 'accessToken' isn't defined for the type 'GoogleSignInAuthentication'.
Cause 1 of 3
The code creates its own GoogleSignIn object
You seedoesn't have an unnamed constructor, at a line like GoogleSignIn(scopes: [...])
Check
The package's migration notes say GoogleSignIn is a singleton in 7 and that an explicit initialize step must run exactly once before any other method. Scopes are no longer passed to a constructor.
grep -rn "GoogleSignIn(" libFix
Use GoogleSignIn.instance and call initialize at startup. On Android, a project without google-services.json passes the web application client ID as serverClientId.
import 'package:google_sign_in/google_sign_in.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await GoogleSignIn.instance.initialize(
serverClientId: 'YOUR_WEB_CLIENT_ID.apps.googleusercontent.com',
);
runApp(const MyApp());
}Verify
flutter analyze no longer reports the constructor error.
flutter analyze libConfirmed by github.com
Cause 2 of 3
signIn and signInSilently were renamed and split
You seesignIn or signInSilently isn't defined for the type 'GoogleSignIn'
Check
In 7, authenticate() handles the interactive sign-in and attemptLightweightAuthentication() replaces the silent one, which may now show a small UI. Web does not support authenticate(); supportsAuthenticate() tells you at runtime.
grep -rnE "\.signIn\(|signInSilently" libFix
Call the new methods. Pass scopes you will need soon as scopeHint so supported platforms can ask for them in the same screen.
final signIn = GoogleSignIn.instance;
// app start: restore a previous session if possible
final restored = await signIn.attemptLightweightAuthentication();
// sign-in button (not on web, which uses renderButton)
if (signIn.supportsAuthenticate()) {
final account = await signIn.authenticate(scopeHint: ['email']);
}Verify
Run on a device and sign in; the account email prints and analyze is clean.
flutter runConfirmed by github.com
Cause 3 of 3
accessToken is read from authentication
You seeThe getter 'accessToken' isn't defined for the type 'GoogleSignInAuthentication'
Check
Authentication (who the user is) and authorization (which scopes the app may use) are separate in 7. account.authentication still gives the idToken; the access token now comes from authorizationClient.
grep -rn "accessToken" libFix
Ask for an existing grant first and only show the consent UI when there is none.
const scopes = ['https://www.googleapis.com/auth/drive.readonly'];
final idToken = account.authentication.idToken;
final authz =
await account.authorizationClient.authorizationForScopes(scopes) ??
await account.authorizationClient.authorizeScopes(scopes);
final accessToken = authz.accessToken;Verify
The access token is non-null after the user grants the scopes, and API calls with it succeed.
flutter analyze libConfirmed by pub.dev
How do I stop it coming back?
- Pin plugins with a caret on the major version (google_sign_in: ^6.2.0) so pub upgrade never crosses a major release by surprise.
- Read a plugin's MIGRATION.md before raising its major version.
- Keep sign-in code in one service class so an API rewrite touches one file.
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.