Application Entry Point
The application starts atmain.dart:6, which serves as the root entry point:
main.dart
The app uses Material Design with a teal and blue color scheme. The theme is consistently applied throughout the application.
Navigation Flow
Trackmart implements a hierarchical navigation structure with three main levels:Root Page (Authentication Gateway)
root_page.dart manages the authentication state and determines which screen to display.Authentication States:notSignedIn→ Shows LoginPagesignedIn→ Shows HomePageloading→ Shows loading spinner
root_page.dart
Home Page (Main Application Hub)
Once authenticated, users land on
home_page.dart, which provides a tabbed interface with three main sections:- Chats Tab: View and initiate conversations with drivers
- Request Tab: Create new delivery requests
- Orders Tab: View order history and status
Navigation Diagram
Core Components
1. Authentication & Session Management
TheRootPage component manages the entire authentication lifecycle:
The app uses Firebase Cloud Messaging (FCM) for push notifications. Device tokens are stored in both Firebase Realtime Database and Cloud Firestore for redundancy.
2. Push Notifications
Trackmart integrates Firebase Cloud Messaging with local notifications:root_page.dart
3. Home Page Architecture
The home page uses aStatefulWidget with TabController for navigation:
Home Page Structure
Home Page Structure
home_page.dart
4. Real-time Location Tracking
The app continuously tracks user location and updates Firebase:home_page.dart
5. Map Integration
Trackmart uses Mapbox for map visualization and routing:MapPage
Displays real-time delivery tracking with route visualization between driver and buyer locations.Features:
- Live driver location updates
- Route polyline rendering
- ETA calculation
- Distance display
MapPage2
Shows all available drivers on a map with their distances and ETAs.Features:
- Driver selection
- Distance sorting
- Real-time availability
- Quick driver info
Route Calculation
map.dart
6. Chat System
The chat feature enables direct communication between buyers and drivers:chat.dart
Application Lifecycle
Authentication
- User signs in via phone number or email
- FCM token is registered
- User data is loaded from SharedPreferences
Main Flow
- Location tracking starts
- User can browse drivers, create orders, and chat
- Real-time updates via Firebase listeners
Key Design Patterns
StatefulWidget Pattern
Trackmart extensively usesStatefulWidget for managing component state:
- RootPage: Manages authentication state
- HomePage/TabbedGuy: Manages tab navigation and order state
- MapPage: Manages map state and real-time location
- Chat: Manages message state and input
Stream-Based Updates
The app leverages Firebase streams for real-time data:Async/Await for Data Loading
Asynchronous operations are handled with Future-based patterns:Performance Optimizations
Firebase Persistence
Both Realtime Database and Firestore have offline persistence enabled for better performance and offline capability.
Image Caching
Uses
cached_network_image package for efficient image loading and caching.Location Filtering
Location updates are filtered to 10-meter changes to reduce unnecessary database writes.
Stream Optimization
Firebase queries use proper indexing and limit clauses to minimize data transfer.
Related Documentation
Database Schema
Learn about the Firebase database structure
State Management
Understand how app state is managed
API Integration
Explore external API integrations