Skip to content

Commit

Permalink
refactor: update example app to support initializing default apps fro…
Browse files Browse the repository at this point in the history
…m Android resource strings
  • Loading branch information
Salakar committed May 3, 2022
1 parent 4b97133 commit 3e644b5
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 52 deletions.
Expand Up @@ -6,6 +6,7 @@
<activity
android:name="io.flutter.embedding.android.FlutterActivity"
android:launchMode="singleTop"
android:exported="true"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
Expand Down
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="default_web_client_id" translatable="false">406099696497-a12gakvts4epfk5pkio7dphc1anjiggc.apps.googleusercontent.com</string>
<string name="firebase_database_url" translatable="false">https://flutterfire-e2e-tests-default-rtdb.europe-west1.firebasedatabase.app</string>
<string name="gcm_defaultSenderId" translatable="false">406099696497</string>
<string name="google_api_key" translatable="false">AIzaSyCdRjCVZlhrq72RuEklEyyxYlBRCYhI2Sw</string>
<string name="google_app_id" translatable="false">1:406099696497:android:0d4ed619c031c0ac3574d0</string>
<string name="google_crash_reporting_api_key" translatable="false">AIzaSyCdRjCVZlhrq72RuEklEyyxYlBRCYhI2Sw</string>
<string name="google_storage_bucket" translatable="false">flutterfire-e2e-tests.appspot.com</string>
<string name="project_id" translatable="false">flutterfire-e2e-tests</string>
</resources>
Expand Up @@ -6,7 +6,6 @@ buildscript {

dependencies {
classpath 'com.android.tools.build:gradle:4.1.2'
classpath 'com.google.gms:google-services:4.3.4'
}
}

Expand Down

This file was deleted.

@@ -0,0 +1,87 @@
// 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:
return ios;
case TargetPlatform.macOS:
return macos;
default:
throw UnsupportedError(
'DefaultFirebaseOptions are not supported for this platform.',
);
}
}

static const FirebaseOptions web = FirebaseOptions(
apiKey: 'AIzaSyB7wZb2tO1-Fs6GbDADUSTs2Qs3w08Hovw',
appId: '1:406099696497:web:87e25e51afe982cd3574d0',
messagingSenderId: '406099696497',
projectId: 'flutterfire-e2e-tests',
authDomain: 'flutterfire-e2e-tests.firebaseapp.com',
databaseURL:
'https://flutterfire-e2e-tests-default-rtdb.europe-west1.firebasedatabase.app',
storageBucket: 'flutterfire-e2e-tests.appspot.com',
measurementId: 'G-JN95N1JV2E',
);

static const FirebaseOptions android = FirebaseOptions(
apiKey: 'AIzaSyCdRjCVZlhrq72RuEklEyyxYlBRCYhI2Sw',
appId: '1:406099696497:android:0d4ed619c031c0ac3574d0',
messagingSenderId: '406099696497',
projectId: 'flutterfire-e2e-tests',
databaseURL:
'https://flutterfire-e2e-tests-default-rtdb.europe-west1.firebasedatabase.app',
storageBucket: 'flutterfire-e2e-tests.appspot.com',
);

static const FirebaseOptions ios = FirebaseOptions(
apiKey: 'AIzaSyDooSUGSf63Ghq02_iIhtnmwMDs4HlWS6c',
appId: '1:406099696497:ios:acd9c8e17b5e620e3574d0',
messagingSenderId: '406099696497',
projectId: 'flutterfire-e2e-tests',
databaseURL:
'https://flutterfire-e2e-tests-default-rtdb.europe-west1.firebasedatabase.app',
storageBucket: 'flutterfire-e2e-tests.appspot.com',
androidClientId:
'406099696497-tvtvuiqogct1gs1s6lh114jeps7hpjm5.apps.googleusercontent.com',
iosClientId:
'406099696497-taeapvle10rf355ljcvq5dt134mkghmp.apps.googleusercontent.com',
iosBundleId: 'io.flutter.plugins.firebase.tests',
);

static const FirebaseOptions macos = FirebaseOptions(
apiKey: 'AIzaSyDooSUGSf63Ghq02_iIhtnmwMDs4HlWS6c',
appId: '1:406099696497:ios:acd9c8e17b5e620e3574d0',
messagingSenderId: '406099696497',
projectId: 'flutterfire-e2e-tests',
databaseURL:
'https://flutterfire-e2e-tests-default-rtdb.europe-west1.firebasedatabase.app',
storageBucket: 'flutterfire-e2e-tests.appspot.com',
androidClientId:
'406099696497-tvtvuiqogct1gs1s6lh114jeps7hpjm5.apps.googleusercontent.com',
iosClientId:
'406099696497-taeapvle10rf355ljcvq5dt134mkghmp.apps.googleusercontent.com',
iosBundleId: 'io.flutter.plugins.firebase.tests',
);
}
44 changes: 28 additions & 16 deletions packages/firebase_core/firebase_core/example/lib/main.dart
Expand Up @@ -3,9 +3,10 @@
// found in the LICENSE file.

import 'dart:async';
import 'package:firebase_core_example/firebase_config.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';

void main() => runApp(const MyApp());

Expand All @@ -14,23 +15,27 @@ class MyApp extends StatelessWidget {

String get name => 'foo';

FirebaseOptions get firebaseOptions => const FirebaseOptions(
appId: '1:448618578101:ios:0b650370bb29e29cac3efc',
apiKey: 'AIzaSyAgUhHU8wSJgO5MVNy95tMT07NEjzMOfz0',
projectId: 'react-native-firebase-testing',
messagingSenderId: '448618578101',
);

Future<void> initializeDefault() async {
FirebaseApp app = await Firebase.initializeApp(
options: DefaultFirebaseConfig.platformOptions,
options: DefaultFirebaseOptions.currentPlatform,
);
print('Initialized default app $app');
}

Future<void> initializeDefaultFromAndroidResource() async {
if (defaultTargetPlatform != TargetPlatform.android || kIsWeb) {
print('Not running on Android, skipping');
return;
}
FirebaseApp app = await Firebase.initializeApp();
print('Initialized default app $app from Android resource');
}

Future<void> initializeSecondary() async {
FirebaseApp app =
await Firebase.initializeApp(name: name, options: firebaseOptions);
FirebaseApp app = await Firebase.initializeApp(
name: name,
options: DefaultFirebaseOptions.currentPlatform,
);

print('Initialized $app');
}
Expand All @@ -41,9 +46,9 @@ class MyApp extends StatelessWidget {
}

void options() {
final FirebaseApp app = Firebase.app(name);
final FirebaseApp app = Firebase.app();
final options = app.options;
print('Current options for app $name: $options');
print('Current options for app ${app.name}: $options');
}

Future<void> delete() async {
Expand All @@ -69,21 +74,28 @@ class MyApp extends StatelessWidget {
onPressed: initializeDefault,
child: const Text('Initialize default app'),
),
if (defaultTargetPlatform == TargetPlatform.android && !kIsWeb)
ElevatedButton(
onPressed: initializeDefaultFromAndroidResource,
child: const Text(
'Initialize default app from Android resources',
),
),
ElevatedButton(
onPressed: initializeSecondary,
child: const Text('Initialize secondary app'),
),
ElevatedButton(
onPressed: apps,
child: const Text('Get apps'),
child: const Text('List apps'),
),
ElevatedButton(
onPressed: options,
child: const Text('List options'),
child: const Text('List default options'),
),
ElevatedButton(
onPressed: delete,
child: const Text('Delete app'),
child: const Text('Delete secondary app'),
),
],
),
Expand Down

0 comments on commit 3e644b5

Please sign in to comment.