From b620f60c2f4b1f6e8fb0002ff2b0487e95a00b16 Mon Sep 17 00:00:00 2001 From: Koen Van Looveren Date: Tue, 21 Nov 2023 21:56:26 +0100 Subject: [PATCH] fix(cli): Add firebase config --- .github/workflows/deploy.yml | 2 +- .gitignore | 5 +- lib/firebase_init.dart | 4 +- lib/firebase_options.dart | 63 ++++++++++++++++++++++++++ lib/main.dart | 2 - lib/util/firebase/firebase_config.dart | 27 ----------- 6 files changed, 67 insertions(+), 36 deletions(-) create mode 100644 lib/firebase_options.dart delete mode 100644 lib/util/firebase/firebase_config.dart diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 909c466..f958449 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -27,7 +27,7 @@ jobs: channel: ${{ steps.fvm-config-action.outputs.FLUTTER_CHANNEL }} - run: flutter packages get - run: dart analyze - - run: flutter build web --dart-define=FIREBASE_API_KEY=$FIREBASE_API_KEY --dart-define=FIREBASE_APP_ID=${{secrets.FIREBASE_APP_ID}} --dart-define=FIREBASE_MESSAGING_SENDER_ID=${{secrets.FIREBASE_MESSAGING_SENDER_ID}} --dart-define=FIREBASE_PROJECT_ID=${{secrets.FIREBASE_PROJECT_ID}} --dart-define=FIREBASE_AUTH_DOMAIN=${{secrets.FIREBASE_AUTH_DOMAIN}} --dart-define=FIREBASE_STORAGE_BUCKET=${{secrets.FIREBASE_STORAGE_BUCKET}} --dart-define=FIREBASE_MEASUREMENT_ID=${{secrets.FIREBASE_MEASUREMENT_ID}} + - run: flutter build web - name: Upload artifact uses: actions/upload-pages-artifact@v1 with: diff --git a/.gitignore b/.gitignore index 9b5af4b..2deb7c3 100644 --- a/.gitignore +++ b/.gitignore @@ -44,7 +44,4 @@ app.*.map.json /android/app/release # FVM -.fvm/flutter_sdk - -# Firebase -lib/firebase_options.dart \ No newline at end of file +.fvm/flutter_sdk \ No newline at end of file diff --git a/lib/firebase_init.dart b/lib/firebase_init.dart index d5f56c3..16ab6f1 100644 --- a/lib/firebase_init.dart +++ b/lib/firebase_init.dart @@ -1,9 +1,9 @@ import 'package:firebase_core/firebase_core.dart'; import 'package:flutter_belgium/di/injectable.dart'; +import 'package:flutter_belgium/firebase_options.dart'; import 'package:flutter_belgium/repo/login_repo.dart'; -import 'package:flutter_belgium/util/firebase/firebase_config.dart'; Future initFirebase() async { - await Firebase.initializeApp(options: FirebaseConfig.currentPlatform); + await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); getIt().init(); } diff --git a/lib/firebase_options.dart b/lib/firebase_options.dart new file mode 100644 index 0000000..13b8241 --- /dev/null +++ b/lib/firebase_options.dart @@ -0,0 +1,63 @@ +// 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: + throw UnsupportedError( + 'DefaultFirebaseOptions have not been configured for android - ' + 'you can reconfigure this by running the FlutterFire CLI again.', + ); + 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: 'AIzaSyDQo5SlRMWBIyzjNN4MvMaO1fhjs83Nui8', + appId: '1:755875347425:web:4f90d9bec1021df43630a0', + messagingSenderId: '755875347425', + projectId: 'flutter-belgium', + authDomain: 'flutter-belgium.firebaseapp.com', + storageBucket: 'flutter-belgium.appspot.com', + measurementId: 'G-XT58Y3Y0E6', + ); +} diff --git a/lib/main.dart b/lib/main.dart index 6453a31..57faebf 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -4,8 +4,6 @@ import 'package:flutter_belgium/di/injectable.dart'; import 'package:flutter_belgium/firebase_init.dart'; Future main() async { - const value = String.fromEnvironment('FIREBASE_PROJECT_ID'); - print(value); configureDependencies(); await initFirebase(); runApp(const MyApp()); diff --git a/lib/util/firebase/firebase_config.dart b/lib/util/firebase/firebase_config.dart deleted file mode 100644 index 7f29a78..0000000 --- a/lib/util/firebase/firebase_config.dart +++ /dev/null @@ -1,27 +0,0 @@ -import 'package:firebase_core/firebase_core.dart'; -import 'package:flutter/foundation.dart'; -// import 'package:flutter_belgium/firebase_options.dart'; - -class FirebaseConfig { - static FirebaseOptions get currentPlatform { - if (kIsWeb) { - return _web; - } - throw UnsupportedError('This platform is not supported'); - // try { - // return DefaultFirebaseOptions.currentPlatform; - // } catch (e) { - // return DefaultFirebaseOptions.currentPlatform; - // } - } - - static const FirebaseOptions _web = FirebaseOptions( - apiKey: String.fromEnvironment('FIREBASE_API_KEY'), - appId: String.fromEnvironment('FIREBASE_APP_ID'), - messagingSenderId: String.fromEnvironment('FIREBASE_MESSAGING_SENDER_ID'), - projectId: String.fromEnvironment('FIREBASE_PROJECT_ID'), - authDomain: String.fromEnvironment('FIREBASE_AUTH_DOMAIN'), - storageBucket: String.fromEnvironment('FIREBASE_STORAGE_BUCKET'), - measurementId: String.fromEnvironment('FIREBASE_MEASUREMENT_ID'), - ); -}