Where can i find google app id, api key, project id and gcm sender id in cloud firestore - flutter

I had this sample code, but I am not sure where can I find all the fields in my Firebase console.
final FirebaseApp app = await FirebaseApp.configure(
name: 'test',
options: const FirebaseOptions(
googleAppID: '1:1234567:ios:987654',
gcmSenderID: '987654321',
apiKey: 'ABC123456789DEF',
projectID: 'projectId',
),
);

You can find it in GoogleServicesInfo.plist file.
You should be able to see like:
<key>GOOGLE_APP_ID</key>
<string>1:111111:ios:222222</string>
<key>GCM_SENDER_ID</key>
<string>1234567890</string>
<key>API_KEY</key>
<string>ThisIsMyApiKey111</string>
<key>PROJECT_ID</key>
<string>yourId</string>

Related

flutter web not working due to await statement

I am having issues with Flutter web when I use await statement,
void main() async {
//debugPaintSizeEnabled = true;
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
this will not display anything on the browser and throws and error:
ChromeProxyService: Failed to evaluate expression 'title': InternalError: Expression evaluation in async frames is not supported. No frame with index 39..
I am stuck :(
debugging testing nothing worked
Run flutter channel stable followed by flutter upgrade --force
When using Firebase, you need to initalize it with options for the specific platform that you are using. Here goes and example on how to configure it for Flutter Web:
import 'package:firebase_core/firebase_core.dart' show FirebaseOptions;
void main() async {
//debugPaintSizeEnabled = true;
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options = FirebaseOptions(
apiKey: 'YOUR API KEY',
appId: 'YOUR APP ID',
messagingSenderId: 'YOUR MESSAGING SENDER ID',
projectId: 'YOUR PROJECT NAME',
authDomain: 'YOUR AUTH DOMAIN (IF YOU HAVE)',
databaseURL: 'YOUR DATABASE URL (IF YOU USE FIREBASEDATABASE)',
storageBucket: 'YOUR STORAGE BUCKET',
)
);
runApp(MyApp());
}
All this information is available on your Firebase Project Console, just search for it. Hope it helps!

How to share Flutter source code for projects linked to Firebase?

I have a Flutter project linked to my Firebase account (using FlutterFire CLI).
Now that I finished the project I want to sell the source code.
How can I change the Firebase account linked to this project?
When using FlutterFire CLI, it generates a file called firebase_options.dart containing Firebase options for each platform like this:
static const FirebaseOptions android = FirebaseOptions(
apiKey: '-------',
appId: '------',
messagingSenderId: '-----',
projectId: '----------',
storageBucket: '--------',
  );
Do I have just to change these values? If yes, where can I find all of them?
main.dart
import 'firebase_options.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(const MyApp());
}
Full firebase_options.dart file
// File generated by FlutterFire CLI.
// ignore_for_file: lines_longer_than_80_chars, avoid_classes_with_only_static_members
import 'package:firebase_core/firebase_core.dart' show FirebaseOptions;
import 'package:flutter/foundation.dart'
show defaultTargetPlatform, kIsWeb, TargetPlatform;
/// Default [FirebaseOptions] for use with your Firebase apps.
///
/// Example:
/// ```dart
/// import 'firebase_options.dart';
/// // ...
/// await Firebase.initializeApp(
/// options: DefaultFirebaseOptions.currentPlatform,
/// );
/// ```
class DefaultFirebaseOptions {
static FirebaseOptions get currentPlatform {
if (kIsWeb) {
return web;
}
switch (defaultTargetPlatform) {
case TargetPlatform.android:
return android;
case TargetPlatform.iOS:
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for ios - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
case TargetPlatform.macOS:
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for macos - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
case TargetPlatform.windows:
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for windows - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
case TargetPlatform.linux:
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for linux - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
default:
throw UnsupportedError(
'DefaultFirebaseOptions are not supported for this platform.',
);
}
}
static const FirebaseOptions web = FirebaseOptions(
apiKey: '------',
appId: '------',
messagingSenderId: '-----',
projectId: '------',
authDomain: '--------',
storageBucket: '--------',
measurementId: '--------',
);
static const FirebaseOptions android = FirebaseOptions(
apiKey: '----',
appId: '----',
messagingSenderId: '--------',
projectId: '------',
storageBucket: '--------',
);
}
I tried to change the values (in firebase_options.dart) and that caused this error:
E/flutter (26545): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: [core/duplicate-app] A Firebase App named "[DEFAULT]" already exists
it throws this error(duplicateApp from method_channel_firebase.dart):
// If there is a native default app and the user provided options do a soft
// check to see if options are roughly identical (so we don't unnecessarily
// throw on minor differences such as platform specific keys missing
// e.g. hot reloads/restarts).
if (defaultApp != null && _options != null) {
if (_options.apiKey != defaultApp.options.apiKey ||
(_options.databaseURL != null &&
_options.databaseURL != defaultApp.options.databaseURL) ||
(_options.storageBucket != null &&
_options.storageBucket != defaultApp.options.storageBucket)) {
// Options are different; throw.
throw duplicateApp(defaultFirebaseAppName);
}
// Options are roughly the same; so we'll return the existing app.
}
You can change the firebase account linked to this project. This error that you are seeing
E/flutter (26545): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: [core/duplicate-app] A Firebase App named "[DEFAULT]" already exists
is caused by the original gradle sync operation generating a Google-Services.json file and using it within the app. To remove this error, switch into the android folder from your main flutter project and run
./gradlew clean
This command calls the gradle wrapper which then cleans the project and brings it back to its original state. The flutter team uses a default empty flutter_options.dart file for their projects. You may want to consider doing that if you are seeing the source code to someone. I would just package instructions for how to configure their project to work with a new Firebase project that they would select.

firebase storage: uploading jpg casuing Could not load the default credentials. on Node.js

const { initializeApp } = require("firebase-admin/app");
const { getStorage } = require("firebase-admin/storage");
const firebaseConfig = {
apiKey: "ajsoidjof",
authDomain: "asodijfo",
projectId: "sihfiasd",
storageBucket: "sadjofjosad",
messagingSenderId: "2039023423",
appId: "saoijdofijo3ijo2",
measurementId: "sijdofijeadsf",
};
initializeApp(firebaseConfig);
const bucket = getStorage().bucket();
bucket.upload("./1.jpg");
This causes Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information. error. And, how can I upload the 1.jpg to just the main storage folder?
You're using the Firebase Admin SDK for Node.js, but then trying to initialize it with the configuration data for a client-side SDK. That won't work, so you'll either have to initialize the Admin SDK as shown here or use the client-side Node.js SDK.

Android Enterprises Device Enrollment Stuck with NodeJs Generated QR Code with Service Account Authentication

As mentioned in the google documents i have tested the following process
URL to quick start: https://colab.research.google.com/github/google/android-management-api-samples/blob/master/notebooks/quickstart.ipynb#scrollTo=pjHfDSb8BoBP
Create Enterprise
Create Policy
Enroll the device
Then I have used the NODEJS API of Android Enterprises to develop the server based solution, which is working fine as per the documentation for all the functions such as get, create, delete the policy, devices, enterprises.
The issue i am facing is with the QR code generated from NODE application, when i scan the QR code generated from NODEJS application, the device got stuck at system update.
Following is my Policy update function
router.post('/update/:id', async function(req, res) {
const {title,policy_body,update_mask,enroll_url} = req.body;
// here we are callng the android managment API to and then the response we will update to database
const amApiBody = {
name: policy_body.name,
updateMask:update_mask,
requestBody:policy_body
}
const policy_update_response = await amApi.updatePolicy(amApiBody);
const p = await policyModel.update(req.params.id,title,policy_update_response,enroll_url);
res.json(p)
});
AmAPI file
this.updatePolicy = async function (body)
{
const auth = new google.auth.GoogleAuth({
scopes: ['https://www.googleapis.com/auth/androidmanagement'],
});
const authClient = await auth.getClient();
google.options({auth: authClient});
// Get the list of available policies
const res = await androidmanagement.enterprises.policies.patch(body);
console.log('requestFinalBody=',body);
return res.data;
}
Following is my policy data obtained by running above function
policy_create_response= {
name: 'enterprises/LC019rjnor/policies/policy1',
version: '14',
applications: [
{
packageName: 'com.google.samples.apps.iosched',
installType: 'FORCE_INSTALLED',
autoUpdateMode: 'AUTO_UPDATE_HIGH_PRIORITY'
},
{
packageName: 'com.dekaisheng.courier',
installType: 'FORCE_INSTALLED',
autoUpdateMode: 'AUTO_UPDATE_HIGH_PRIORITY'
}
],
keyguardDisabledFeatures: [ 'KEYGUARD_DISABLED_FEATURE_UNSPECIFIED' ],
defaultPermissionPolicy: 'GRANT',
uninstallAppsDisabled: true,
keyguardDisabled: true,
tetheringConfigDisabled: true,
dataRoamingDisabled: true,
networkEscapeHatchEnabled: true,
bluetoothDisabled: true,
debuggingFeaturesAllowed: true,
funDisabled: true,
kioskCustomLauncherEnabled: true
}
Note i have exported the variable to the terminal as follows before running the app, the auth.json is the service account credential file.
export GOOGLE_APPLICATION_CREDENTIALS="/Users/Mac/Projects/wajid/mdm/server/env/auth.json"
Thanks for the help in advance
I figured out that in nodeJS API I was passing wrong property name of Policy value in the request body.
Code before fix
parent: this.getParent(policyName),
requestBody:{
“name”: “my_policy"
}
Code after fix
parent: this.getParent(policyName),
requestBody:{
"policyName”: “my_policy"
}

Firebase RTDB Flutter app: Multiple Databases

So, I am using the Blaze plan in Firebase and I have multiple realtime databases. I was wondering how I can connect to a specific one through my Flutter app.
FirebaseDatabase.instance.reference(); connects me to the default database, but how can I connect to another one?
Using FirebaseDatabase.instance is just a shorthand notation to getting the default FirebaseApp instance, which is typically auto-initialized from the values in your google-services.json/google-services.info.plist
You can explicitly initialize a FirebaseApp with configuration data in your code. A snippet of the relevant code from an app I happen to be working on:
final FirebaseApp app = await FirebaseApp.configure(
name: "defaultAppName",
options: Platform.isIOS
? const FirebaseOptions(
googleAppID: '....',
gcmSenderID: '...',
databaseURL: '...',
)
: const FirebaseOptions(
googleAppID: '...',
apiKey: '...',
databaseURL: '...',
),
);*/
FirebaseDatabase(app: app).setPersistenceEnabled(true);
FirebaseDatabase(app: app).reference().child("/rounds/r1").orderByValue().onChildAdded.forEach((event) => {
print(event.snapshot.value)
});