diff --git a/README.md b/README.md index 0f71bac..33ab6a8 100644 --- a/README.md +++ b/README.md @@ -17,3 +17,12 @@ Build the app ```shell flutter build --dart-define MAPBOX_ACCESS_TOKEN=... ``` + +Copy the Firebase config from https://console.firebase.google.com/project//settings/general/ and use it the same way: + +```shell +--dart-define FIREBASE_API_KEY=... +--dart-define FIREBASE_APP_ID=.... +--dart-define FIREBASE_MESSAGING_SENDER_ID=... +--dart-define FIREBASE_PROJECT_ID=... +``` diff --git a/green_walking/lib/config.dart b/green_walking/lib/config.dart index cda3ecc..f360c30 100644 --- a/green_walking/lib/config.dart +++ b/green_walking/lib/config.dart @@ -10,3 +10,10 @@ class CustomMapboxStyles { static const String outdoor = 'mapbox://styles/xennis/ckfbioyul1iln1ap0pm5hrcgy'; static const String satellite = 'mapbox://styles/xennis/ckfc5mxh33tjg19qvk6m5f5hj'; } + +// env +const mapboxAccessToken = String.fromEnvironment("MAPBOX_ACCESS_TOKEN"); +const firebaseApiKey = String.fromEnvironment("FIREBASE_API_KEY"); +const firebaseAppId = String.fromEnvironment("FIREBASE_APP_ID"); +const firebaseMessagingSenderId = String.fromEnvironment("FIREBASE_MESSAGING_SENDER_ID"); +const firebaseProjectId = String.fromEnvironment("FIREBASE_PROJECT_ID"); diff --git a/green_walking/lib/firebase_options.dart b/green_walking/lib/firebase_options.dart new file mode 100644 index 0000000..17786bd --- /dev/null +++ b/green_walking/lib/firebase_options.dart @@ -0,0 +1,62 @@ +// 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; + +import 'config.dart'; + +/// 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) { + 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: + 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 android = FirebaseOptions( + apiKey: firebaseApiKey, + appId: firebaseAppId, + messagingSenderId: firebaseMessagingSenderId, + projectId: firebaseProjectId, + ); +} diff --git a/green_walking/lib/main.dart b/green_walking/lib/main.dart index e6247cc..bcfc9aa 100644 --- a/green_walking/lib/main.dart +++ b/green_walking/lib/main.dart @@ -6,6 +6,7 @@ import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart'; import 'package:provider/provider.dart'; +import 'config.dart'; import 'firebase_options.dart'; import 'provider/prefs_provider.dart'; import 'routes.dart'; @@ -19,7 +20,7 @@ Future main() async { // Pass all uncaught errors from the framework to Crashlytics. FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterError; - MapboxOptions.setAccessToken(const String.fromEnvironment("MAPBOX_ACCESS_TOKEN")); + MapboxOptions.setAccessToken(mapboxAccessToken); runApp(const GreenWalkingApp()); }