initialize method
Initialize the database provider with configuration settings
Implementation
@override
Future<void> initialize(Map<String, dynamic> config) async {
if (_initialized) {
return;
}
final serviceAccount = _loadServiceAccount(config);
final credentials = ServiceAccountCredentials.fromJson(serviceAccount);
_projectId =
_stringFromConfig(config, 'projectId') ??
_stringFromMap(serviceAccount, 'project_id') ??
_stringFromConfig(config, 'project') ??
'';
if (_projectId.isEmpty) {
throw ArgumentError('Missing required config: projectId');
}
_databaseId = _stringFromConfig(config, 'databaseId') ??
_stringFromConfig(config, 'database') ??
'(default)';
final scopes = _scopesFromConfig(config) ??
[firestore.FirestoreApi.datastoreScope];
_client = await clientViaServiceAccount(credentials, scopes);
_api = firestore.FirestoreApi(_client!);
_initialized = true;
}