Skip to content

Commit

Permalink
feat: improve implementation FlutterFire CLI for multi env
Browse files Browse the repository at this point in the history
  • Loading branch information
Lzyct committed Feb 27, 2024
1 parent c931424 commit bb4220a
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 149 deletions.
15 changes: 14 additions & 1 deletion .env.prd.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
{
"ENV": "production",
"BASE_URL": "https://reqres.in"
"BASE_URL": "https://reqres.in",
"ANDROID_API_KEY": "AIzaSyCdU1UveIWYwX-Lsmtl7pIigbu5lug-pTU",
"ANDROID_APP_ID": "1:933342696488:android:2a6b2649b130a09e87511d",
"ANDROID_SENDER_ID": "933342696488",
"ANDROID_PROJECT_ID": "mobile-app-bd59b",
"ANDROID_STORAGE_BUCKET": "mobile-app-bd59b.appspot.com",
"IOS_API_KEY": "AIzaSyAPG4_LhFSS94Jez8k20Mu4i7cyCn26hzc",
"IOS_APP_ID": "1:933342696488:ios:3ddb617c88b0363187511d",
"IOS_SENDER_ID": "933342696488",
"IOS_PROJECT_ID": "mobile-app-bd59b",
"IOS_STORAGE_BUCKET": "mobile-app-bd59b.appspot.com",
"IOS_ANDROID_CLIENT_ID": "933342696488-i2co7br6pib2js7a8vsjpio4164n0qci.apps.googleusercontent.com",
"IOS_IOS_CLIENT_ID": "933342696488-ekbqsc1q8pkvk61nj5p0f04061ivr0ug.apps.googleusercontent.com",
"IOS_BUNDLE_ID": "com.lazycatlabs.auths"
}
15 changes: 14 additions & 1 deletion .env.stg.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
{
"ENV": "staging",
"BASE_URL": "https://reqres.in"
"BASE_URL": "https://reqres.in",
"ANDROID_API_KEY": "AIzaSyAXDLxYlgYywHeVs8Ch8uOq2t2BmtjOM0s",
"ANDROID_APP_ID": "1:520881115656:android:5ce1808f01692ab2fd77bd",
"ANDROID_SENDER_ID": "520881115656",
"ANDROID_PROJECT_ID": "sample-49e7c",
"ANDROID_STORAGE_BUCKET": "sample-49e7c.appspot.com",
"IOS_API_KEY": "AIzaSyCgylLbnzngRGnumT5dnyfx4foQ2Qdu3dY",
"IOS_APP_ID": "1:520881115656:ios:db518045ccad29fffd77bd",
"IOS_SENDER_ID": "520881115656",
"IOS_PROJECT_ID": "sample-49e7c",
"IOS_STORAGE_BUCKET": "sample-49e7c.appspot.com",
"IOS_ANDROID_CLIENT_ID": "520881115656-a76c2vaojcsa2kj1qk243eclfna6j6ff.apps.googleusercontent.com",
"IOS_IOS_CLIENT_ID": "520881115656-e14k5pcrklmsih46r01nh1fm9gt4oaf0.apps.googleusercontent.com",
"IOS_BUNDLE_ID": "com.lazycatlabs.auths.stg"
}
3 changes: 1 addition & 2 deletions lib/utils/services/firebase/firebase.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export 'firebase_crashlogger.dart';
export 'firebase_options_prd.dart';
export 'firebase_options_stg.dart';
export 'firebase_options.dart';
export 'firebase_services.dart';
55 changes: 55 additions & 0 deletions lib/utils/services/firebase/firebase_options.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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: DefaultFirebaseOptionsStg.currentPlatform,
/// );
/// ```
class DefaultFirebaseOptions {
static FirebaseOptions get currentPlatform {
if (kIsWeb) {
throw UnsupportedError(
'DefaultFirebaseOptionsStg have not been configured for web - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
}
switch (defaultTargetPlatform) {
case TargetPlatform.android:
return android;
case TargetPlatform.iOS:
return ios;
default:
throw UnsupportedError(
'DefaultFirebaseOptionsStg are not supported for this platform.',
);
}
}

static const FirebaseOptions android = FirebaseOptions(
apiKey: String.fromEnvironment("ANDROID_API_KEY"),
appId: String.fromEnvironment("ANDROID_APP_ID"),
messagingSenderId: String.fromEnvironment("ANDROID_SENDER_ID"),
projectId: String.fromEnvironment("ANDROID_PROJECT_ID"),
storageBucket: String.fromEnvironment("ANDROID_STORAGE_BUCKET"),
);

static const FirebaseOptions ios = FirebaseOptions(
apiKey: String.fromEnvironment("IOS_API_KEY"),
appId: String.fromEnvironment("IOS_APP_ID"),
messagingSenderId: String.fromEnvironment("IOS_SENDER_ID"),
projectId: String.fromEnvironment("IOS_PROJECT_ID"),
storageBucket: String.fromEnvironment("IOS_STORAGE_BUCKET"),
androidClientId: String.fromEnvironment("IOS_ANDROID_CLIENT_ID"),
iosClientId: String.fromEnvironment("IOS_IOS_CLIENT_ID"),
iosBundleId: String.fromEnvironment("IOS_BUNDLE_ID"),
);
}
72 changes: 0 additions & 72 deletions lib/utils/services/firebase/firebase_options_prd.dart

This file was deleted.

70 changes: 0 additions & 70 deletions lib/utils/services/firebase/firebase_options_stg.dart

This file was deleted.

4 changes: 1 addition & 3 deletions lib/utils/services/firebase/firebase_services.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ mixin FirebaseServices {
static Future<void> init() async {
/// Initialize Firebase
await Firebase.initializeApp(
options: const String.fromEnvironment("ENV") == "staging"
? DefaultFirebaseOptionsStg.currentPlatform
: DefaultFirebaseOptionsPrd.currentPlatform,
options: DefaultFirebaseOptions.currentPlatform,
);
// Pass all uncaught errors from the framework to Crashlytics.
// FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterError;
Expand Down

0 comments on commit bb4220a

Please sign in to comment.