From b8444bda3abaae33ddb5e760b9c2a32b23b6c3c3 Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 18 Feb 2023 16:03:22 +0100 Subject: [PATCH 1/5] feat: Firebase is initialized for production and development --- android/app/build.gradle | 4 +- android/app/google-services.json | 70 ++++++++------------------------ ios/firebase_app_id_file.json | 6 +-- lib/bootstrap.dart | 12 +++++- lib/firebase_options.dart | 8 ++-- lib/firebase_options_dev.dart | 69 +++++++++++++++++++++++++++++++ lib/main_development.dart | 2 +- lib/main_production.dart | 2 +- lib/main_staging.dart | 2 +- 9 files changed, 108 insertions(+), 67 deletions(-) create mode 100644 lib/firebase_options_dev.dart diff --git a/android/app/build.gradle b/android/app/build.gradle index 847a441..1cc3a81 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -52,7 +52,7 @@ android { defaultConfig { applicationId "dev.flutterexplained.community_app" - minSdkVersion flutter.minSdkVersion + minSdkVersion 23 targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName @@ -77,7 +77,7 @@ android { } flavorDimensions "default" - productFlavors { + productFlavors { production { dimension "default" applicationIdSuffix "" diff --git a/android/app/google-services.json b/android/app/google-services.json index b68662c..2625a9d 100644 --- a/android/app/google-services.json +++ b/android/app/google-services.json @@ -1,76 +1,40 @@ { "project_info": { - "project_number": "416647339946", - "project_id": "flutter-explained-community", - "storage_bucket": "flutter-explained-community.appspot.com" + "project_number": "904342392027", + "project_id": "fe-community-dev", + "storage_bucket": "fe-community-dev.appspot.com" }, "client": [ { "client_info": { - "mobilesdk_app_id": "1:416647339946:android:aeee24df2f82f9d1c9d5d3", + "mobilesdk_app_id": "1:904342392027:android:6e23ad729fa926912ad0fe", "android_client_info": { - "package_name": "com.example.community_app" - } - }, - "oauth_client": [ - { - "client_id": "416647339946-pcveajdsiu5vvsvhuil30jp316kvba35.apps.googleusercontent.com", - "client_type": 3 - } - ], - "api_key": [ - { - "current_key": "AIzaSyBarisN1l9qgQtmg1hzcEC3FRGw_PrUt8A" - } - ], - "services": { - "appinvite_service": { - "other_platform_oauth_client": [ - { - "client_id": "416647339946-pcveajdsiu5vvsvhuil30jp316kvba35.apps.googleusercontent.com", - "client_type": 3 - }, - { - "client_id": "416647339946-g6tmvohc21sce0i12if4g819ptfq5svl.apps.googleusercontent.com", - "client_type": 2, - "ios_info": { - "bundle_id": "com.example.verygoodcore.community-app" - } - } - ] - } - } - }, - { - "client_info": { - "mobilesdk_app_id": "1:416647339946:android:6a6e9cdce67d0712c9d5d3", - "android_client_info": { - "package_name": "com.example.verygoodcore.community_app" + "package_name": "dev.flutterexplained.community_app" } }, "oauth_client": [ { - "client_id": "416647339946-pcveajdsiu5vvsvhuil30jp316kvba35.apps.googleusercontent.com", + "client_id": "904342392027-v6bpbj6kq2igl1nh1atihvtnrg4be8gv.apps.googleusercontent.com", "client_type": 3 } ], "api_key": [ { - "current_key": "AIzaSyBarisN1l9qgQtmg1hzcEC3FRGw_PrUt8A" + "current_key": "AIzaSyAvJzjCY2WLdII87qwpQQvUqjw0RcRisGM" } ], "services": { "appinvite_service": { "other_platform_oauth_client": [ { - "client_id": "416647339946-pcveajdsiu5vvsvhuil30jp316kvba35.apps.googleusercontent.com", + "client_id": "904342392027-v6bpbj6kq2igl1nh1atihvtnrg4be8gv.apps.googleusercontent.com", "client_type": 3 }, { - "client_id": "416647339946-g6tmvohc21sce0i12if4g819ptfq5svl.apps.googleusercontent.com", + "client_id": "904342392027-q5sb99te7uc07m0td6lg8f9kfo4cbohg.apps.googleusercontent.com", "client_type": 2, "ios_info": { - "bundle_id": "com.example.verygoodcore.community-app" + "bundle_id": "dev.flutterexplained.community-app.dev" } } ] @@ -79,34 +43,34 @@ }, { "client_info": { - "mobilesdk_app_id": "1:416647339946:android:3b8cbe30444a07bbc9d5d3", + "mobilesdk_app_id": "1:904342392027:android:b2991e3e0348c5482ad0fe", "android_client_info": { - "package_name": "dev.flutterexplained.community_app" + "package_name": "dev.flutterexplained.community_app.dev" } }, "oauth_client": [ { - "client_id": "416647339946-pcveajdsiu5vvsvhuil30jp316kvba35.apps.googleusercontent.com", + "client_id": "904342392027-v6bpbj6kq2igl1nh1atihvtnrg4be8gv.apps.googleusercontent.com", "client_type": 3 } ], "api_key": [ { - "current_key": "AIzaSyBarisN1l9qgQtmg1hzcEC3FRGw_PrUt8A" + "current_key": "AIzaSyAvJzjCY2WLdII87qwpQQvUqjw0RcRisGM" } ], "services": { "appinvite_service": { "other_platform_oauth_client": [ { - "client_id": "416647339946-pcveajdsiu5vvsvhuil30jp316kvba35.apps.googleusercontent.com", + "client_id": "904342392027-v6bpbj6kq2igl1nh1atihvtnrg4be8gv.apps.googleusercontent.com", "client_type": 3 }, { - "client_id": "416647339946-g6tmvohc21sce0i12if4g819ptfq5svl.apps.googleusercontent.com", + "client_id": "904342392027-q5sb99te7uc07m0td6lg8f9kfo4cbohg.apps.googleusercontent.com", "client_type": 2, "ios_info": { - "bundle_id": "com.example.verygoodcore.community-app" + "bundle_id": "dev.flutterexplained.community-app.dev" } } ] diff --git a/ios/firebase_app_id_file.json b/ios/firebase_app_id_file.json index cda477e..1655b6e 100644 --- a/ios/firebase_app_id_file.json +++ b/ios/firebase_app_id_file.json @@ -1,7 +1,7 @@ { "file_generated_by": "FlutterFire CLI", "purpose": "FirebaseAppID & ProjectID for this Firebase app in this directory", - "GOOGLE_APP_ID": "1:416647339946:ios:7a555c9101c8b460c9d5d3", - "FIREBASE_PROJECT_ID": "flutter-explained-community", - "GCM_SENDER_ID": "416647339946" + "GOOGLE_APP_ID": "1:904342392027:ios:4a2e611a4843f6df2ad0fe", + "FIREBASE_PROJECT_ID": "fe-community-dev", + "GCM_SENDER_ID": "904342392027" } \ No newline at end of file diff --git a/lib/bootstrap.dart b/lib/bootstrap.dart index 82a2574..7a2769e 100644 --- a/lib/bootstrap.dart +++ b/lib/bootstrap.dart @@ -6,6 +6,8 @@ import 'package:community_app/firebase_options.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/widgets.dart'; +enum Environment { dev, staging, prod } + class AppBlocObserver extends BlocObserver { const AppBlocObserver(); @@ -22,14 +24,20 @@ class AppBlocObserver extends BlocObserver { } } -Future bootstrap(FutureOr Function() builder) async { +Future bootstrap( + FutureOr Function() builder, Environment environment) async { WidgetsFlutterBinding.ensureInitialized(); + FlutterError.onError = (details) { log(details.exceptionAsString(), stackTrace: details.stack); }; Bloc.observer = const AppBlocObserver(); - await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); + + await Firebase.initializeApp( + name: '$environment', + options: DefaultFirebaseOptions.currentPlatform, + ); await runZonedGuarded( () async => runApp(await builder()), diff --git a/lib/firebase_options.dart b/lib/firebase_options.dart index 799447d..c935168 100644 --- a/lib/firebase_options.dart +++ b/lib/firebase_options.dart @@ -2,7 +2,7 @@ // 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 TargetPlatform, defaultTargetPlatform, kIsWeb; + show defaultTargetPlatform, kIsWeb, TargetPlatform; /// Default [FirebaseOptions] for use with your Firebase apps. /// @@ -60,12 +60,12 @@ class DefaultFirebaseOptions { static const FirebaseOptions ios = FirebaseOptions( apiKey: 'AIzaSyBuKomYEqhbFRtOZWQcNOMrDyUd_XFAAvU', - appId: '1:416647339946:ios:7a555c9101c8b460c9d5d3', + appId: '1:416647339946:ios:51dbead1e89cf4edc9d5d3', messagingSenderId: '416647339946', projectId: 'flutter-explained-community', storageBucket: 'flutter-explained-community.appspot.com', iosClientId: - '416647339946-rrjtr8rgl3r5fgtdam9ms3slu91snflm.apps.googleusercontent.com', - iosBundleId: 'dev.flutterexplained.community-app', + '416647339946-58vodha5kfr0oh3v6343dd7pf9rhjfc4.apps.googleusercontent.com', + iosBundleId: 'dev.explained.comm', ); } diff --git a/lib/firebase_options_dev.dart b/lib/firebase_options_dev.dart new file mode 100644 index 0000000..b46bc0a --- /dev/null +++ b/lib/firebase_options_dev.dart @@ -0,0 +1,69 @@ +// 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_dev.dart'; +/// // ... +/// await Firebase.initializeApp( +/// options: DefaultFirebaseOptions.currentPlatform, +/// ); +/// ``` +class DefaultFirebaseOptions { + static FirebaseOptions get currentPlatform { + if (kIsWeb) { + throw UnsupportedError( + 'DefaultFirebaseOptions 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; + 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 android = FirebaseOptions( + apiKey: 'AIzaSyAvJzjCY2WLdII87qwpQQvUqjw0RcRisGM', + appId: '1:904342392027:android:6e23ad729fa926912ad0fe', + messagingSenderId: '904342392027', + projectId: 'fe-community-dev', + storageBucket: 'fe-community-dev.appspot.com', + ); + + static const FirebaseOptions ios = FirebaseOptions( + apiKey: 'AIzaSyAcA5u44DhgvVnILATaOM_7TAp-vXatL2U', + appId: '1:904342392027:ios:4a2e611a4843f6df2ad0fe', + messagingSenderId: '904342392027', + projectId: 'fe-community-dev', + storageBucket: 'fe-community-dev.appspot.com', + iosClientId: '904342392027-q5sb99te7uc07m0td6lg8f9kfo4cbohg.apps.googleusercontent.com', + iosBundleId: 'dev.flutterexplained.community-app.dev', + ); +} diff --git a/lib/main_development.dart b/lib/main_development.dart index 107ac95..514d91e 100644 --- a/lib/main_development.dart +++ b/lib/main_development.dart @@ -2,5 +2,5 @@ import 'package:community_app/app/app.dart'; import 'package:community_app/bootstrap.dart'; void main() { - bootstrap(() => const App()); + bootstrap(() => const App(), Environment.dev); } diff --git a/lib/main_production.dart b/lib/main_production.dart index 107ac95..0e97670 100644 --- a/lib/main_production.dart +++ b/lib/main_production.dart @@ -2,5 +2,5 @@ import 'package:community_app/app/app.dart'; import 'package:community_app/bootstrap.dart'; void main() { - bootstrap(() => const App()); + bootstrap(() => const App(), Environment.prod); } diff --git a/lib/main_staging.dart b/lib/main_staging.dart index 107ac95..743ef85 100644 --- a/lib/main_staging.dart +++ b/lib/main_staging.dart @@ -2,5 +2,5 @@ import 'package:community_app/app/app.dart'; import 'package:community_app/bootstrap.dart'; void main() { - bootstrap(() => const App()); + bootstrap(() => const App(), Environment.staging); } From cf3f27412d05bcfd15f0856974d204c5c706f930 Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 18 Feb 2023 16:54:19 +0100 Subject: [PATCH 2/5] cleanup: Fixed the default case warning --- lib/firebase_options_dev.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/firebase_options_dev.dart b/lib/firebase_options_dev.dart index b46bc0a..eb62a5d 100644 --- a/lib/firebase_options_dev.dart +++ b/lib/firebase_options_dev.dart @@ -42,10 +42,12 @@ class DefaultFirebaseOptions { 'DefaultFirebaseOptions have not been configured for linux - ' 'you can reconfigure this by running the FlutterFire CLI again.', ); - default: + case TargetPlatform.fuchsia: throw UnsupportedError( - 'DefaultFirebaseOptions are not supported for this platform.', + 'DefaultFirebaseOptions have not been configured for fuchsia - ' + 'you can reconfigure this by running the FlutterFire CLI again.', ); + break; } } From e9e9434699121bf3e60122aba0c4b6b1c4372b8d Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 20 Feb 2023 22:46:57 +0100 Subject: [PATCH 3/5] cleanup: Minor cleanup of dart format --- lib/firebase_options_dev.dart | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/firebase_options_dev.dart b/lib/firebase_options_dev.dart index eb62a5d..3b25639 100644 --- a/lib/firebase_options_dev.dart +++ b/lib/firebase_options_dev.dart @@ -45,7 +45,7 @@ class DefaultFirebaseOptions { case TargetPlatform.fuchsia: throw UnsupportedError( 'DefaultFirebaseOptions have not been configured for fuchsia - ' - 'you can reconfigure this by running the FlutterFire CLI again.', + 'you can reconfigure this by running the FlutterFire CLI again.', ); break; } @@ -65,7 +65,8 @@ class DefaultFirebaseOptions { messagingSenderId: '904342392027', projectId: 'fe-community-dev', storageBucket: 'fe-community-dev.appspot.com', - iosClientId: '904342392027-q5sb99te7uc07m0td6lg8f9kfo4cbohg.apps.googleusercontent.com', + iosClientId: + '904342392027-q5sb99te7uc07m0td6lg8f9kfo4cbohg.apps.googleusercontent.com', iosBundleId: 'dev.flutterexplained.community-app.dev', ); } From ef61be265fe791bbdc596fa9c25927e70035556a Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 20 Feb 2023 22:47:23 +0100 Subject: [PATCH 4/5] cleanup: Added a missing trailing comma --- lib/bootstrap.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/bootstrap.dart b/lib/bootstrap.dart index 7a2769e..cee83ae 100644 --- a/lib/bootstrap.dart +++ b/lib/bootstrap.dart @@ -25,7 +25,9 @@ class AppBlocObserver extends BlocObserver { } Future bootstrap( - FutureOr Function() builder, Environment environment) async { + FutureOr Function() builder, + Environment environment, +) async { WidgetsFlutterBinding.ensureInitialized(); FlutterError.onError = (details) { From aad2f876de52b542a6e79c10ce4c99ad685404a0 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 20 Feb 2023 22:49:37 +0100 Subject: [PATCH 5/5] cleanup: Removed some analyzer issues --- lib/firebase_options.dart | 2 +- lib/firebase_options_dev.dart | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/firebase_options.dart b/lib/firebase_options.dart index c935168..a1de709 100644 --- a/lib/firebase_options.dart +++ b/lib/firebase_options.dart @@ -2,7 +2,7 @@ // 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; + show TargetPlatform, defaultTargetPlatform, kIsWeb; /// Default [FirebaseOptions] for use with your Firebase apps. /// diff --git a/lib/firebase_options_dev.dart b/lib/firebase_options_dev.dart index 3b25639..1720f50 100644 --- a/lib/firebase_options_dev.dart +++ b/lib/firebase_options_dev.dart @@ -2,7 +2,7 @@ // 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; + show TargetPlatform, defaultTargetPlatform, kIsWeb; /// Default [FirebaseOptions] for use with your Firebase apps. /// @@ -47,7 +47,6 @@ class DefaultFirebaseOptions { 'DefaultFirebaseOptions have not been configured for fuchsia - ' 'you can reconfigure this by running the FlutterFire CLI again.', ); - break; } }