Search code examples
flutterdartgoogle-api-services-jobs

AuthClient isn't a type so it can't be used as a type argument - Dart package googleapis_auth


I don't know why I get the above error. My packages are correctly installed. It is not a problem with my linter, as the problem also prevents compilation. I am using version 1.3.1 of googleapis_auth. It is the latest at the time of writing. Plus, the extract code is just copy-pasted from the pub.dev docs. Below is my code.

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:googleapis_auth/auth_io.dart' as auth;

class GmailButton extends StatelessWidget {
   GmailButton({Key? key}) : super(key: key);
Widget build(BuildContext context){
return(
      Container()
    );
  }
    // Obtain an access token
// Use service account credentials to get an authenticated and auto refreshing client.
Future<AuthClient> obtainAuthenticatedClient() async {
  final accountCredentials = ServiceAccountCredentials.fromJson({
    "private_key_id": "<please fill in>",
    "private_key": "<please fill in>",
    "client_email": "<please fill in>@developer.gserviceaccount.com",
    "client_id": "<please fill in>.apps.googleusercontent.com",
    "type": "service_account"
  });
  var scopes = ['https://mail.google.com'];

  AuthClient client = await clientViaServiceAccount(accountCredentials, scopes);

  return client; // Remember to close the client when you are finished with it.
}
    // Send the email
}

Solution

  • I should have written auth.AuthClient instead as I named the import auth. Same for the other members of the Googleapis_auth package members that I did not mention.