A real-time college bus tracking app built with Flutter and Firebase. Students can track buses live on a map, and designated drivers can broadcast their GPS location β all in real-time.
- π Authentication β Email/password signup & login via Firebase Auth
- π Bus Listing β View all college buses with live Active/Idle status
- π Driver Mode β Claim a bus and broadcast GPS location in real-time (one driver per bus)
- π Tracker Mode β Track a bus live on Google Maps with route directions
- πΊοΈ Google Maps Integration β Directions, walking navigation, and route visualization
- π‘οΈ Admin Panel β Manage buses and routes
- β‘ Real-time Updates β Powered by Cloud Firestore real-time listeners
lib/
βββ main.dart # App entry point, Firebase init, auth routing
βββ firebase_options.dart # Auto-generated Firebase config (gitignored)
βββ models/
β βββ bus_model.dart # Bus data model with Firestore serialization
β βββ bus_stop_model.dart # Bus stop data model
βββ services/
β βββ auth_service.dart # Firebase Auth wrapper (sign in/up/out)
β βββ firestore_service.dart # Firestore CRUD, bus claiming, GPS streams
βββ screens/
β βββ login_screen.dart # Login UI
β βββ signup_screen.dart # Signup UI
β βββ bus_list_screen.dart # List of all buses with status
β βββ driver_mode_screen.dart # Driver GPS broadcasting screen
β βββ tracker_screen.dart # Live bus tracking map (student view)
β βββ admin_login_screen.dart # Admin authentication
β βββ admin_panel_screen.dart # Admin bus/route management
βββ widgets/
βββ bus_card.dart # Reusable bus card widget
assets/
βββ map.html # Google Maps WebView with JS functions
Before setting up, make sure you have the following installed:
| Tool | Version | Check |
|---|---|---|
| Flutter SDK | 3.10+ | flutter --version |
| Dart SDK | 3.10+ | dart --version |
| Android Studio | Latest | For Android emulator & SDK |
| Firebase CLI | Latest | npm install -g firebase-tools |
| FlutterFire CLI | Latest | dart pub global activate flutterfire_cli |
| Node.js & npm | 18+ | node --version |
git clone https://github.com/YOUR_USERNAME/VCE-BusTracking.git
cd VCE-BusTrackingflutter pub getThis project uses Firebase for authentication and real-time database. You need to configure it for your own Firebase project.
firebase loginThis command auto-generates google-services.json, GoogleService-Info.plist, and lib/firebase_options.dart:
# If 'flutterfire' is not on your PATH, use the full path:
# Windows: & "$env:LOCALAPPDATA\Pub\Cache\bin\flutterfire.bat" configure --project=YOUR_PROJECT_ID
# macOS/Linux: ~/.pub-cache/bin/flutterfire configure --project=YOUR_PROJECT_ID
flutterfire configure --project=YOUR_PROJECT_IDNote: Replace
YOUR_PROJECT_IDwith your Firebase project ID (e.g.,vce-bustracking).
In the Firebase Console:
- Authentication β Sign-in method β Enable Email/Password
- Cloud Firestore β Create database β Start in test mode
Go to Firestore β + Start collection β Collection ID: buses
Add documents with these fields:
| Field | Type | Example Value |
|---|---|---|
name |
string | Bus 1 |
route |
string | Ameerpet β VCE College |
That's all you need β the activeDriverId, lat, lng fields are set automatically by the app.
This app uses Google Maps JavaScript API and Directions API.
- Go to Google Cloud Console
- Create or select a project
- Enable these APIs:
- Maps JavaScript API
- Directions API
- Go to Credentials β Create an API Key
For the WebView map β open assets/map.html and replace the placeholder in the <script> tag at the bottom:
<script
src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY_HERE&libraries=geometry,directions&callback=initMap"
async defer>
</script>For Android native β open android/app/src/main/AndroidManifest.xml and replace the API key:
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="YOUR_API_KEY_HERE" />
β οΈ Do NOT commit your API key to git. Themap.htmlandAndroidManifest.xmlfiles contain your key locally. Consider using environment variables orlocal.propertiesfor production.
# List available emulators
flutter emulators
# Launch an emulator
flutter emulators --launch <emulator_name>
# Run the app
flutter runTo generate a release APK:
flutter build apk --releaseThe APK will be at: build/app/outputs/flutter-apk/app-release.apk
These files contain sensitive API keys and are not included in the repo:
| File | How to Generate |
|---|---|
android/app/google-services.json |
flutterfire configure or download from Firebase Console |
ios/Runner/GoogleService-Info.plist |
flutterfire configure or download from Firebase Console |
lib/firebase_options.dart |
flutterfire configure |
| Field | Type | Description |
|---|---|---|
name |
string | Bus display name (e.g., "Bus 1") |
route |
string | Route description |
activeDriverId |
string | null | UID of current driver (null = idle) |
activeDriverName |
string | null | Display name of current driver |
lat |
number | null | Current latitude (set by driver) |
lng |
number | null | Current longitude (set by driver) |
lastUpdated |
timestamp | null | Last GPS update time |
stops |
array | List of route stops with lat/lng |
| Field | Type | Description |
|---|---|---|
email |
string | User email |
name |
string | Display name |
role |
string | "student" or "driver" |
createdAt |
timestamp | Account creation time |
flutter emulators --launch Medium_Phone_API_36.1
flutter run- Enable Developer Mode and USB Debugging on your Android phone
- Connect via USB
- Run
flutter run
You need two devices/emulators running simultaneously:
- Device 1: Login as driver β tap "Drive" on a bus
- Device 2: Login as student β tap "Track" on the same bus
- The student should see the driver's location moving in real-time
Tip: You can also manually update
lat/lngfields in the Firebase Console to simulate bus movement while testing tracker mode on a single device.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Follow the Setup Guide to configure Firebase
- Make your changes
- Test on an emulator or device
- Commit (
git commit -m 'Add amazing feature') - Push (
git push origin feature/amazing-feature) - Open a Pull Request