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_dotenvfor 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.jsonfile 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-Exampleflutter pub get- Open
android/gradle.properties - Delete the line
org.gradle.java.home=valueor change with your defined Java Home Path.
- Download and install Firebase CLI (you may use npm or use standalone package).
- Make sure
firebasecommand 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
Overviewand clickAdd App > Android. Then, just follow the instructions (make sure the Android package name is the same as yourandroid/app/build.gradleapplicationId). - After Android app created in Firebase Console, navigate to
Overviewand clickBuild > AuthenticationandBuild > 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 toandroidfolder). Then, run.\gradlew signingReportor./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
Generaltab, scroll to the bottom. ClickAdd fingerprintand 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_clithenflutterfire 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 androidvalues insidelib/firebase_options.dartto.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.jsonENCRYPTION_KEYandIV_KEYbased 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.