Firebase Integration
Elite Quiz uses Firebase for authentication, real-time database operations, and cloud storage. This guide will walk you through integrating Firebase with your app.
Creating a Firebase Project
- Go to the Firebase Console
- Click on "Add project" and follow the prompts to create a new project
- Enter a project name and accept the Firebase terms
- Choose whether to enable Google Analytics (recommended)
- Complete the project setup
After creating the project, you'll be taken to the Firebase project dashboard:
Adding Your App to Firebase
Adding Android App
- In the Firebase console, click on the Android icon to add an Android app
- Enter your app's package name (the one you configured in the previous section)
- Enter an app nickname (optional)
- Enter your app's SHA-1 signing certificate (for Google Sign-In to work properly)
- Click "Register app"
- Download the
google-services.json
file - Click "Next" and follow the remaining setup instructions
- Place the
google-services.json
file in theandroid/app
directory of your Flutter project
Adding iOS App
- In the Firebase console, click on the iOS icon to add an iOS app
- Enter your app's Bundle ID (found in the
ios/Runner.xcodeproj/project.pbxproj
file) - Enter an app nickname (optional)
- Enter your App Store ID (optional)
- Click "Register app"
- Download the
GoogleService-Info.plist
file - Click "Next" and follow the remaining setup instructions
- Place the
GoogleService-Info.plist
file in theios/Runner
directory of your Flutter project
Enabling Firebase Authentication
Elite Quiz supports multiple authentication methods. Here's how to enable them:
- In the Firebase console, go to Authentication > Sign-in method
- Enable the authentication methods you want to use:
- Email/Password
- Phone
- Apple (for iOS)
Configuring Google Sign-In
Google Sign-In is enabled by default when you add Firebase Authentication. Make sure you've added your SHA-1 fingerprint to your Firebase project.
Configuring Facebook Sign-In
To enable Facebook authentication:
- Create a Facebook Developer account and app at developers.facebook.com
- Configure your Facebook app for authentication
- Add the Facebook App ID and App Secret to Firebase Authentication
Configuring Phone Authentication
To enable Phone authentication:
- In the Firebase console, go to Authentication > Sign-in method
- Enable Phone authentication
- Add your test phone numbers if using in development
Setting Up Firebase for Battles
Elite Quiz uses Firebase Realtime Database for real-time battle functionality. To set this up:
- In the Firebase console, go to Realtime Database
- Click "Create Database"
- Choose a location (preferably close to your target audience)
- Start in test mode, then adjust security rules later
Connecting to Admin Panel
The final step is to connect your app to your Admin Panel:
- Open the file
lib/utils/constant.dart
in your project - Look for the BASE_URL constant and update it with your Admin Panel URL:
const String BASE_URL = "https://your-admin-panel-url.com/api/";
Make sure to include the trailing slash at the end of the URL.
Testing Firebase Integration
After completing all the steps above, restart your app and test the following:
- User registration and login
- Social authentication methods (Google, Facebook, etc.)
- Real-time battle functionality
If any issues occur, check the Firebase console logs and your app logs for detailed error messages.