A Flutter project demonstrating a secure implementation of the Model-View-Controller (MVC) architecture integrated with Firebase for authentication and Firestore for data management. This project includes features like user authentication, cart management, and secure environment variable handling.
- MVC Architecture: Clean separation of concerns between Models, Views, and Controllers.
- Firebase Integration:
- Authentication (Email/Password and Google Sign-In).
- Firestore for real-time database operations.
- Secure Environment Variables: Uses
flutter_secure_dotenv
for managing sensitive keys. - Cross-Platform Support: Works on Android, iOS, Web, Windows, macOS, and Linux.
Before running this project, ensure you have the following installed:
- Flutter SDK (version 3.6.0 or higher).
- Firebase CLI for setting up Firebase.
- A Firebase project configured with:
- Firebase Authentication.
- Firestore Database.
- A valid
encryption_key.json
file for secure environment variable handling.
Follow these steps to set up and run the project:
git clone https://github.com/DSC-UNSRI/Secure-MVC-Flutter-Firebase-Example.git
cd Secure-MVC-Flutter-Firebase-Example
flutter pub get
- Open
android/gradle.properties
- Delete the line
org.gradle.java.home=value
or change with your defined Java Home Path.
- Download and install Firebase CLI (you may use npm or use standalone package).
- Make sure
firebase
command is recognized (run in CMD). If not, make sure to have the firebase tools defined in environment variable path. - Navigate to Firebase Console and click
Create a Firebase project
. Then, just follow the instructions. - After created, navigate to
Overview
and clickAdd App > Android
. Then, just follow the instructions (make sure the Android package name is the same as yourandroid/app/build.gradle
applicationId). - After Android app created in Firebase Console, navigate to
Overview
and clickBuild > Authentication
andBuild > Firestore Database
(just follow the instructions on creation, choose the closest server with your country (e.g. Jakarta), use Test Mode Rules at the moment). - Back to your IDE or Code Editor, open up terminal and run
cd android
(navigate toandroid
folder). Then, run.\gradlew signingReport
or./gradlew signingReport
. It should show your keystore's SHA1 and SHA-256. - Copy the SHA1 and SHA-256 (enter each) to
Firebase Console > Overview > Android App (Name) > Click Settings Icon
. - Under
General
tab, scroll to the bottom. ClickAdd fingerprint
and input the SHA1 then SHA-256 value. - Back to your IDE or Code Editor, open up terminal and run
firebase login
(just follow the instructions to login your Google Account [use the same as your Firebase Account]). - After successfully logged in, run
dart pub global activate flutterfire_cli
thenflutterfire configure --project=YOUR-FIREBASE-PROJECT-ID
(configure only for Android, use Space to disable other platforms). It will generate and replacelib/firebase_options.dart
.
- Add all
FirebaseOptions android
values insidelib/firebase_options.dart
to.env
. Look at the this original repositorylib/firebase_options.dart
(before you replace it using flutterfire configure) to modify and proceed (don't push API keys to source control, bud). - Run
dart run build_runner build --define flutter_secure_dotenv_generator:flutter_secure_dotenv=OUTPUT_FILE=encryption_key.json
. - Change
.vscode/launch.json
ENCRYPTION_KEY
andIV_KEY
based on generatedencryption_key.json
(root-level folder). - Use
Run and Debug
(CTRL + SHIFT + D) feature and debug the app using your favorite Android emulator or via USB debugging.