Skip to content

This is a Proof of Concept (POC) for It's Urgent Project for GSoC'24.

Notifications You must be signed in to change notification settings

0xharkirat/its_urgent_poc_public

Repository files navigation

It's Urgent POC

Static Badge Flutter Firebase

Note: Use CTRL+click (on Windows and Linux) or CMD+click (on MacOS) for opening all the links in new tab.

Please open issues if anything goes wrong, I am happy to assist & resolve.

This is a Proof of Concept (POC) for It's Urgent Project for GSoC'24.

  • Working Demo & Apk (does not require any setup):

    • Watch the working Demo Video here: https://youtu.be/__nhs4On2zI (1.5x speed recommended).
    • Download this Android .apk for testing (You need to allow installation from unknown source when installing the app).
  • Running the App Using Flutter on your machine/device (Setup required):

    • This public repo is clone of my private repo which contains all the firebase files, secrets & apis.
    • This is a public repo, it does not contain any firebase functionlity.
    • You need to add firebase project by following these simple instructions which only requires some clicks, copy & paste.
    • For more important notes regarding this poc, see this section.
    • You can also learn from these codelabs

Steps to add your Firebase project in this project.

Prerequisites:

  1. Check your Flutter installation using: flutter doctor -v.

  2. Fork & clone this repo.

  3. cd <this repo>.

  4. Open in the Terminal/Android Studio/VS Code.

  5. Install all plugins using: flutter pub get in the root folder of the project.

  6. For iOS only (Important for getting firebase notifications):

    • If you are only using com.example.<appName> as bundle identifier, Firebase notifications will not work. So follow these steps before adding firebase to your app.
    • Right click on iOS folder -> Open in Xcode -> Runner -> Signing & Capabilities -> Enter some unique Bundle Identifier (like com.<your_unique_name>.<unique_appName> & press enter to check availability. Screenshot 2024-03-18 at 5 18 16 am
    • Then again in VSCode or your editor go to ios/Runner/Info.plist.
    • Change the CFBundleIdentifier to your own unique identifier like I did:
    • Screenshot 2024-03-18 at 4 55 53 am
  7. Go to https://console.firebase.google.com/ to create a Firebase account.

  8. If you haven't already, install the Firebase CLI (Use npm: recommended).

  9. Also remove these lines from .gitignore file at the root folder of your project. Thesse lines were added by me to prevent git to track my firebase files:

/android/app/google-services.json
/ios/firebase_app_id_file.json
/ios/Runner/GoogleService-Info.plist
lib/firebase_options.dart
  1. Now move to Firebase section to add Firebase in your project.

Add Firebase:

Setup Firebase Authentication:

  • Go to Firebase console -> Click on your Project which you added to this flutter app.
  • On the left side menu, click Build -> Authentication -> Get Started -> Sign-in method tab -> Anonymous -> Enable (switch on) -> Save.

Setup Firebase Cloud Firestore:

  • On the left side menu, click Build -> Firestore Database -> Create Database -> Next & Create (With default options).
  • Once created, Select Rules tab -> Paste these rules:
rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    // auth
    match /{document=**} {
      allow read, write: if request.auth != null;
    }
  }
}
  • Publish.

Setup Firebase Cloud Messaging (FCM):

  • Click on Settings Icons next to Project Overview in the left side menu.
  • Click on Project Settings -> Cloud Messaging tab.
  • Click on (three dots) next to Cloud Messaging API (Legacy) Disabled.
  • Click on Manage Api in Google Cloud Console. It will redirect to Google cloud console page.
  • Check your project name at the top and then click enable.
  • Once enabled, come back to the Firebase console to see whether it is enabled.
  • Now copy the Server key.
  • Paste it in lib/secret.dart at <paste your own key from firebase cloud messaging>.
  • All done.

Set up Cloud Messaging for iOS (Important) - needs Apple developer account:

  • Navigate to the Apple developer page, and click Create a key on the Keys tab. image

  • Enter the name for the key and check Apple Push Notifications services (APNs). image

  • Download the key file, which has a .p8 file extension. Take note of Key Id & Team ID (At the top rigth corner): image Screenshot 2024-03-18 at 5 09 29 am

  • In the Firebase console, navigate to the project's Project Settings and choose the Cloud Messaging tab. image

image

  • Upload the APNs key file for the iOS app in the Cloud Messaging tab.
  • Enter the APNs key ID from the Cloud Messaging tab and the team ID, which can be found at the top right corner in the Apple membership center. image

iOS Signing & Capabilites:

  • Again open the project in Xcode.

  • Click on Runner -> Signing & Capabilites -> + Capability Screenshot 2024-03-18 at 5 18 16 am

  • Click on Push Notifications.

  • Enter Push Notifications inside the Capabilties search:

  • Now Search for "Background Modes": image

  • Click on Background modes.

  • Now ensure that both the "Background fetch" and the "Remote notifications" sub-modes are enabled:

ezgif com-avif-to-gif-converter

  • All Done.

Run App

  • Now you can connect physical device or simulator to run using flutter run.
  • If you have multiple devices connected, it will ask you to select one device.
  • iOS simulators have problem showing notifications from Firebase, use physical iOS devices instead.

Some Important notes:

  • This project uses Kotlin 1.8.0, which is required for app_settings plugin.
    • In your android/settings.gradle id "org.jetbrains.kotlin.android" version "1.8.0" apply false
  • In this poc, Notifications only shows when app is in the background mode.
  • For the foreground mode, it requires extra functionality which I will implement using the flutter_local_notifications or awesome_notifications package during my GSoC period.
  • It also does not check for device's DND mode. Full functionality during GSoC period.
  • It is currently using Cloud Messaging API (Legacy) for sending notifications, which is deprecated, I will use Firebase Cloud Messaging API (V1) which is recommended in the full project during my GSoC period.
  • It does not uses any other backend server, cloud functions to handle complex logics such as checking for dnd mode, notifying the sender about challenges etc. as required & mentioned in project page. All functionality will be implemented using Firebase cloud functions, which will also act as security layer for cloud firestore db.
  • Currently Phone numbers are stored as plain numbers, I will implement functionality to store phone number data in encrypted mode using cloud functions.
  • Flutter/Dart plugins used:
    • firebase_core
    • firebase_auth
    • provider
    • cloud_firestore
    • flutter_contacts
    • transparent_image
    • app_settings
    • firebase_messaging
    • http