This guide explains where and how to configure all API keys and endpoints for Study Buddy.
- Quick Start
- Backend API Configuration
- Google Gemini API
- Firebase Configuration
- Environment Variables (Optional)
- Testing Your Configuration
File to edit: lib/core/constants/api_config.dart
abstract final class ApiConfig {
// 1. Your backend API URL
static const String baseUrl = 'https://your-api.studybuddy.id/v1';
// 2. Your Google Gemini API Key
static const String geminiApiKey = 'YOUR_GEMINI_API_KEY';
// 3. API Key for your backend (if required)
static const String apiKey = 'YOUR_BACKEND_API_KEY';
}static const String baseUrl = 'https://your-api.studybuddy.id/v1';What to do:
- Replace with your actual backend API URL
- Include the version path (e.g.,
/v1) - Use HTTPS in production
Examples:
// Development (local)
static const String baseUrl = 'http://192.168.1.100:3000/api';
// Staging
static const String baseUrl = 'https://staging-api.studybuddy.id/v1';
// Production
static const String baseUrl = 'https://api.studybuddy.id/v1';static const String apiKey = '';What to do:
- Leave empty if your backend doesn't require an API key
- Add your API key if you have one
- Get this from your backend's admin panel
All endpoints are defined in ApiEndpoints class in the same file:
abstract final class ApiEndpoints {
// Authentication
static const String login = '/auth/login';
static const String register = '/auth/register';
static const String logout = '/auth/logout';
// VAK Assessment
static const String vakQuestions = '/vak/questions';
static const String vakSubmit = '/vak/submit';
// AI Tutor
static const String tutorChat = '/tutor/chat';
// Schedule Scanner
static const String scannerUpload = '/scanner/upload';
// ... and more
}What to do:
- Modify endpoint paths to match your backend API
- Add new endpoints as needed
Steps:
- Go to Google AI Studio
- Sign in with your Google account
- Click "Create API Key"
- Copy the generated key
static const String geminiApiKey = 'YOUR_GEMINI_API_KEY_HERE';// For text chat (Socratic Tutor)
static const String geminiModel = 'gemini-1.5-flash';
// For vision/OCR tasks
static const String geminiVisionModel = 'gemini-1.5-flash';Available models:
gemini-pro- Original Gemini Pro modelgemini-1.5-pro- Most capable modelgemini-1.5-flash- Fast, efficient (recommended)
The Gemini API is used in:
lib/features/study/data/repositories/tutor_repository.dart- Socratic Tutorlib/features/study/data/repositories/schedule_repository.dart- OCR Processing
Example (Tutor Repository):
// Direct Gemini API call (optional)
final response = await _geminiClient.post(
'/models/${ApiConfig.geminiModel}:generateContent?key=$geminiApiKey',
{
'contents': [
{
'parts': [
{'text': 'Your prompt here'},
],
},
],
},
);Steps:
- Go to Firebase Console
- Click "Add project"
- Follow the setup wizard
- Enable Cloud Messaging
Steps:
-
Install Firebase CLI:
npm install -g firebase-tools
-
Login to Firebase:
firebase login
-
Create Flutter app in Firebase:
cd L:\StudyBuddy flutterfire configure
-
This will:
- Create
lib/firebase_options.dart - Add Firebase configuration for Android & iOS
- Create
Already added to pubspec.yaml:
dependencies:
firebase_core: ^2.x.x
firebase_messaging: ^14.x.x
flutter_local_notifications: ^16.x.xRun:
flutter pub getAndroid:
google-services.jsonβandroid/app/- Update
android/app/build.gradle:apply plugin: 'com.google.gms.google-services'
iOS:
GoogleService-Info.plistβios/Runner/- Update
ios/Runner/AppDelegate.swift:import Firebase FirebaseApp.configure()
Edit: lib/core/services/notification_service.dart
Replace placeholder code with actual Firebase implementation (see comments in file).
Instead of hardcoding API keys, use environment variables.
-
Add dependency:
dependencies: flutter_dotenv: ^5.1.0
-
Create
.envfile (add to.gitignore):GEMINI_API_KEY=your_key_here API_BASE_URL=https://api.studybuddy.id/v1 -
Load in
main.dart:import 'package:flutter_dotenv/flutter_dotenv.dart'; Future<void> main() async { await dotenv.load(fileName: '.env'); // ... rest of main }
-
Use in
api_config.dart:static const String geminiApiKey = String.fromEnvironment('GEMINI_API_KEY');
For different environments (dev, staging, prod), use Flutter build flavors.
Run the app and try:
- Login/Register
- Fetch user profile
- Any API call
Check debug console for logs from ApiClient.
Open lib/features/study/data/repositories/tutor_repository.dart and:
- Uncomment the Gemini API call code
- Send a message in the tutor chat
- Check if you get a response
After Firebase setup:
flutter runCheck console for Firebase initialization logs.
| File | What to Configure |
|---|---|
lib/core/constants/api_config.dart |
Backend URL, Gemini API key, endpoints |
lib/core/services/notification_service.dart |
Firebase notifications |
lib/features/auth/data/repositories/auth_repository.dart |
Auth API calls |
lib/features/study/data/repositories/tutor_repository.dart |
Gemini API for tutor |
lib/features/study/data/repositories/schedule_repository.dart |
OCR API |
android/app/google-services.json |
Firebase Android config |
ios/Runner/GoogleService-Info.plist |
Firebase iOS config |
- Check
api_config.darthas your API key - Restart the app after changing config
- Check your backend URL is correct
- Verify backend is running
- Check internet connection
- Run
flutterfire configure - Ensure
google-services.json/GoogleService-Info.plistare in correct location
- API key might be invalid
- Check API key permissions in Google Cloud Console
- Verify billing is enabled (if required)
- Check the inline comments in each file
- Review
lib/core/constants/api_config.dartfor all configuration options - See placeholder comments (
β οΈ PLACEHOLDER) for implementation hints
Last Updated: March 31, 2026
Version: 1.0.0