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?