1

I have developed a Flutter App to manage users like adding, editing and deleting as an admin. I found firebase_admin package from https://pub.dev/packages/firebase_admin for Flutter but I'm stuck at some error.

I'm using the following dependencies in pubspec.yaml firebase_admin: ^0.1.2+1

I have also created the environment variable in Win10 GOOGLE_APPLICATION_CREDENTIALS=C:\Users\NAME\Downloads\service-account.json

I'm using the following code and I'm getting Unsupported operation: Unsupported platform: android

  var credential = Credentials.applicationDefault();
  credential ??= await Credentials.login();

  var projectId = 'mtm-res-123456';
  // create an app
  var app = FirebaseAdmin.instance.initializeApp(AppOptions(
      credential: credential ?? Credentials.applicationDefault(),
      projectId: projectId,
      storageBucket: '$projectId.appspot.com'));

If I remove the line, credential ??= await Credentials.login(); I'm getting the following error message. I/flutter (14814): Credential implementation provided to initializeApp() via the "credential" property failed to fetch a valid Google OAuth2 access token with the following error: "NoSuchMethodError: The method 'getAccessToken' was called on null.

I have also tried this code,

  var app = FirebaseAdmin.instance.initializeApp(AppOptions(
    credential: FirebaseAdmin.instance.certFromPath('/project/app/service-account.json'),
  ));

In this case, I get the following error message I/flutter (14814): FirebaseAppError(app/invalid-credential): Failed to parse certificate key file: FileSystemException: Cannot open file, path = '/project/app/service-account.json' (OS Error: No such file or directory, errno = 2)

service-account.json is located in same folder as google-services.json.

I'm trying with my emulator.

Please help me. What am I doing wrong?

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
akfaisel
  • 108
  • 5
  • In general, the Firebase Admin SDK isn't meant to be used in frontend apps. They're meant to be used on secure backends where it's safe to store service account credentials. – Doug Stevenson Aug 03 '20 at 06:39
  • Can I create an exclusive Flutter App that runs only on my mobile only securely? May I know what is the purpose of the Firebase Admin SDK for Flutter that is published in https://pub.dev/packages/firebase_admin? – akfaisel Aug 03 '20 at 16:06
  • @akfaisel did you get any solution of this problem? – Ottoman Coder Mar 26 '22 at 16:19

0 Answers0