Set up firebase for flutter using firebase cli: https://firebase.flutter.dev/docs/overview/ #### Table of Contents 1. *[Deploying flutter webapp using Firebase Hosting](https://gist.github.com/maheshmnj/e4a29a387c6e9ad3b71d71d2ca968d0a#1-deploying-flutter-webapp-using-firebase-hosting)* 2. *[Set Firebase messaging notification icon](https://gist.github.com/maheshmnj/e4a29a387c6e9ad3b71d71d2ca968d0a#2-set-firebase-messaging-notification-icon-in-android-app)* 3. *[Send notification to ios simulator/device](https://gist.github.com/maheshmnj/e4a29a387c6e9ad3b71d71d2ca968d0a#2-set-firebase-messaging-notification-icon-in-android-app)* 4. *[CORS issue in firebase storage](https://gist.github.com/maheshmnj/e4a29a387c6e9ad3b71d71d2ca968d0a#4-cors-issue-in-firebase-storage)* 5. *[Firebase analytics](https://gist.github.com/maheshmnj/e4a29a387c6e9ad3b71d71d2ca968d0a#5-firebase-analytics)* 6. *[Google SignIn](https://gist.github.com/maheshmnj/e4a29a387c6e9ad3b71d71d2ca968d0a#6-google-signin) ### 1. Deploying flutter webapp using Firebase Hosting 1. install npm cli 2. Install firebase tools using npm 3. run `firebase login` And then you ar ready to deploy to firebase ``` Maheshs-MacBook-Air-M1:beautiful_snippet mahesh$ flutter pub get flutteRunning "flutter pub get" in beautiful_snippet... 902ms webMaheshs-MacBook-Air-M1:beautiful_snippet mahesh$ flutter build web 💪 Building with sound null safety 💪 Compiling lib/main.dart for the Web... 19.3s Maheshs-MacBook-Air-M1:beautiful_snippet mahesh$ firebase init ######## #### ######## ######## ######## ### ###### ######## ## ## ## ## ## ## ## ## ## ## ## ###### ## ######## ###### ######## ######### ###### ###### ## ## ## ## ## ## ## ## ## ## ## ## #### ## ## ######## ######## ## ## ###### ######## You're about to initialize a Firebase project in this directory: /Users/mahesh/Documents/flutter_projects/beautiful_snippet Before we get started, keep in mind: * You are initializing in an existing Firebase project directory ? Which Firebase CLI features do you want to set up for this folder? Press Space to select features, then Enter to confirm your choices. Hosting: Configure a nd deploy Firebase Hosting sites === Project Setup First, let's associate this project directory with a Firebase project. You can create multiple project aliases by running firebase use --add, but for now we'll just set up a default project. i .firebaserc already has a default project, using beautiful-snippet. === Hosting Setup Your public directory is the folder (relative to your project directory) that will contain Hosting assets to be uploaded with firebase deploy. If you have a build process for your assets, use your build's output directory. ? What do you want to use as your public directory? build/web ? Configure as a single-page app (rewrite all urls to /index.html)? Yes ? Set up automatic builds and deploys with GitHub? No ? File build/web/index.html already exists. Overwrite? No i Skipping write of build/web/index.html i Writing configuration info to firebase.json... i Writing project information to .firebaserc... ✔ Firebase initialization complete! Maheshs-MacBook-Air-M1:beautiful_snippet mahesh$ firebase deploy === Deploying to 'beautiful-snippet'... i deploying hosting i hosting[beautiful-snippet]: beginning deploy... i hosting[beautiful-snippet]: found 13 files in build/web ✔ hosting[beautiful-snippet]: file upload complete i hosting[beautiful-snippet]: finalizing version... ✔ hosting[beautiful-snippet]: version finalized i hosting[beautiful-snippet]: releasing new version... ✔ hosting[beautiful-snippet]: release complete ✔ Deploy complete! Project Console: https://console.firebase.google.com/project/beautiful-snippet/overview Hosting URL: https://beautiful-snippet.web.app Maheshs-MacBook-Air-M1:beautiful_snippet mahesh$ ``` Firebase hosting by default deploys the app to default site to deploy to a another site you need to change the target. -a site deleted cannot be recovered. The example below shows how site was deployed to ```https://vocabhub.web.app``` when the default site was ```https://vocabhub-34c7f.web.app``` - Add to firebase.json ```"site": "vocabhub",``` e.g after adding firebase.json would like this ``` { "hosting": { "public": "build/web", "site": "vocabhub", "ignore": [ "firebase.json", "**/.*", "**/node_modules/**" ], "rewrites": [ { "source": "**", "destination": "/index.html" } ] } } ``` - run the deploy to this hosting command ``` mahesh@Maheshs-MacBook-Air-M1 vocabhub % firebase hosting:sites:list Sites for project vocabhub-34c7f ┌────────────────┬────────────────────────────────┬─────────────────┐ │ Site ID │ Default URL │ App ID (if set) │ ├────────────────┼────────────────────────────────┼─────────────────┤ │ vocabhub-34c7f │ https://vocabhub-34c7f.web.app │ -- │ └────────────────┴────────────────────────────────┴─────────────────┘ mahesh@Maheshs-MacBook-Air-M1 vocabhub % firebase deploy --only hosting:vocabhub === Deploying to 'vocabhub-34c7f'... i deploying hosting i hosting[vocabhub]: beginning deploy... i hosting[vocabhub]: found 13 files in build/web ✔ hosting[vocabhub]: file upload complete i hosting[vocabhub]: finalizing version... ✔ hosting[vocabhub]: version finalized i hosting[vocabhub]: releasing new version... ✔ hosting[vocabhub]: release complete ✔ Deploy complete! Project Console: https://console.firebase.google.com/project/vocabhub-34c7f/overview Hosting URL: https://vocabhub.web.app ``` ### 2. Set Firebase messaging Notification icon in Android app originally posted here https://github.com/flutter/flutter/issues/17941#issuecomment-412242466 ```xml ``` ### 3. Send notification to ios simulator/device Set up push Notifications: https://medium.com/comerge/implementing-push-notifications-in-flutter-apps-aef98451e8f1 _sample push notification payload_ ```json { "aps" : { "alert" : { "title" : "Game Request", "subtitle" : "Five Card Draw", "body" : "Bob wants to play poker" }, "category" : "GAME_INVITATION" }, "gameID" : "12345678" } ``` ``` xcrun simctl push booted com.nevercode.triage assets/api.json ``` ### 4. CORS issue in firebase storage ``` mahesh@Maheshs-MacBook-Air-M1 ~ % cd google-cloud-sdk mahesh@Maheshs-MacBook-Air-M1 google-cloud-sdk % ./install.sh Welcome to the Google Cloud CLI! To help improve the quality of this product, we collect anonymized usage data and anonymized stacktraces when crashes are encountered; additional information is available at . This data is handled in accordance with our privacy policy . You may choose to opt in this collection now (by choosing 'Y' at the below prompt), or at any time in the future by running the following command: gcloud config set disable_usage_reporting false Do you want to help improve the Google Cloud CLI (y/N)? y Your current Google Cloud CLI version is: 392.0.0 The latest available version is: 392.0.0 ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │ Components │ ├───────────────┬──────────────────────────────────────────────────────┬──────────────────────────┬──────────┤ │ Status │ Name │ ID │ Size │ ├───────────────┼──────────────────────────────────────────────────────┼──────────────────────────┼──────────┤ │ Not Installed │ App Engine Go Extensions │ app-engine-go │ 4.0 MiB │ │ Not Installed │ Appctl │ appctl │ 18.5 MiB │ │ Not Installed │ Artifact Registry Go Module Package Helper │ package-go-module │ < 1 MiB │ │ Not Installed │ Cloud Bigtable Command Line Tool │ cbt │ 9.3 MiB │ │ Not Installed │ Cloud Bigtable Emulator │ bigtable │ 5.7 MiB │ │ Not Installed │ Cloud Datalab Command Line Tool │ datalab │ < 1 MiB │ │ Not Installed │ Cloud Datastore Emulator │ cloud-datastore-emulator │ 34.9 MiB │ │ Not Installed │ Cloud Firestore Emulator │ cloud-firestore-emulator │ 39.5 MiB │ │ Not Installed │ Cloud Pub/Sub Emulator │ pubsub-emulator │ 60.7 MiB │ │ Not Installed │ Cloud Run Proxy │ cloud-run-proxy │ 7.4 MiB │ │ Not Installed │ Cloud SQL Proxy │ cloud_sql_proxy │ 7.3 MiB │ │ Not Installed │ Google Cloud Build Local Builder │ cloud-build-local │ 6.2 MiB │ │ Not Installed │ Google Container Registry's Docker credential helper │ docker-credential-gcr │ │ │ Not Installed │ Kustomize │ kustomize │ 7.4 MiB │ │ Not Installed │ Minikube │ minikube │ 27.1 MiB │ │ Not Installed │ Nomos CLI │ nomos │ 23.5 MiB │ │ Not Installed │ On-Demand Scanning API extraction helper │ local-extract │ 10.9 MiB │ │ Not Installed │ Skaffold │ skaffold │ 19.2 MiB │ │ Not Installed │ anthos-auth │ anthos-auth │ 18.2 MiB │ │ Not Installed │ config-connector │ config-connector │ 52.7 MiB │ │ Not Installed │ gcloud Alpha Commands │ alpha │ < 1 MiB │ │ Not Installed │ gcloud Beta Commands │ beta │ < 1 MiB │ │ Not Installed │ gcloud app Java Extensions │ app-engine-java │ 51.9 MiB │ │ Not Installed │ gcloud app PHP Extensions │ app-engine-php │ 21.9 MiB │ │ Not Installed │ gcloud app Python Extensions │ app-engine-python │ 7.8 MiB │ │ Not Installed │ gcloud app Python Extensions (Extra Libraries) │ app-engine-python-extras │ 26.4 MiB │ │ Not Installed │ kpt │ kpt │ 12.6 MiB │ │ Not Installed │ kubectl │ kubectl │ < 1 MiB │ │ Not Installed │ kubectl-oidc │ kubectl-oidc │ 18.2 MiB │ │ Not Installed │ pkg │ pkg │ │ │ Installed │ BigQuery Command Line Tool │ bq │ 1.6 MiB │ │ Installed │ Cloud Storage Command Line Tool │ gsutil │ 15.5 MiB │ │ Installed │ Google Cloud CLI Core Libraries │ core │ 23.8 MiB │ └───────────────┴──────────────────────────────────────────────────────┴──────────────────────────┴──────────┘ To install or remove components at your current SDK version [392.0.0], run: $ gcloud components install COMPONENT_ID $ gcloud components remove COMPONENT_ID To update your SDK installation to the latest version [392.0.0], run: $ gcloud components update To take a quick anonymous survey, run: $ gcloud survey Modify profile to update your $PATH and enable shell command completion? Do you want to continue (Y/n)? y The Google Cloud SDK installer will now prompt you to update an rc file to bring the Google Cloud CLIs into your environment. Enter a path to an rc file to update, or leave blank to use [/Users/mahesh/.zshrc]: Backing up [/Users/mahesh/.zshrc] to [/Users/mahesh/.zshrc.backup]. [/Users/mahesh/.zshrc] has been updated. ==> Start a new shell for the changes to take effect. For more information on how to get started, please visit: https://cloud.google.com/sdk/docs/quickstarts mahesh@Maheshs-MacBook-Air-M1 google-cloud-sdk % gcloud init Welcome! This command will take you through the configuration of gcloud. Settings from your current configuration [cors] are: core: account: email1@example.com disable_usage_reporting: 'True' project: furdle-21410493 Pick configuration to use: [1] Re-initialize this configuration [cors] with new settings [2] Create a new configuration [3] Switch to and re-initialize existing configuration: [default] Please enter your numeric choice: 3 Your current configuration has been set to: [default] You can skip diagnostics next time by using the following flag: gcloud init --skip-diagnostics Network diagnostic detects and fixes local network connection issues. Checking network connection...done. Reachability Check passed. Network diagnostic passed (1/1 checks passed). Choose the account you would like to use to perform operations for this configuration: [1] email1@example.com [2] email2@example.com [3] Log in with a new account Please enter your numeric choice: 2 You are logged in as: [email1@example.com]. Pick cloud project to use: [1] project-1 [2] project-2 [3] project-3 ... ... [14] Project-14 [15] [16] Please enter numeric choice or text value (must exactly match list item): 14 Your current project has been set to: [Project-14]. Not setting default zone/region (this feature makes it easier to use [gcloud compute] by setting an appropriate default value for the --zone and --region flag). See https://cloud.google.com/compute/docs/gcloud-compute section on how to set default compute region and zone manually. If you would like [gcloud init] to be able to do this for you the next time you run it, make sure the Compute Engine API is enabled for your project on the https://console.developers.google.com/apis page. Your Google Cloud SDK is configured and ready to use! * Commands that require authentication will use username@gmail.com by default * Commands will reference project `Project-14` by default Run `gcloud help config` to learn how to change individual settings This gcloud configuration is called [default]. You can create additional configurations if you work with multiple accounts and/or projects. Run `gcloud topic configurations` to learn more. Some things to try next: * Run `gcloud --help` to see the Cloud Platform services you can interact with. And run `gcloud help COMMAND` to get help on any gcloud command. * Run `gcloud topic --help` to learn about advanced features of the SDK like arg files and output formatting * Run `gcloud cheat-sheet` to see a roster of go-to `gcloud` commands. mahesh@Maheshs-MacBook-Air-M1 myproject % gcloud --help mahesh@Maheshs-MacBook-Air-M1 myproject % gsutil cors set cors.json gs://myproject-id.appspot.com Setting CORS on gs://myproject-id.appspot.com/... mahesh@Maheshs-MacBook-Air-M1 myproject % ``` ### 5. Firebase analytics - Add routeObserver to MaterialApp ``` navigatorObservers: [ FirebaseAnalyticsObserver(analytics: firebaseAnalytics), ], ``` - Send events to firebase using `firebaseAnalytics` e.g firebaseAnalytics.setScreen(name:'screenName'); - To test in realtime use debugView enable debug mode ``` adb shell setprop debug.firebase.analytics.app ``` Disable debug mode ``` adb shell setprop debug.firebase.analytics.app .none. ``` ### 6. Google SignIn Generate SHA fingerprint (Mac) ``` keytool -list -v -alias androiddebugkey -keystore ~/.android/debug.keystore ```