Post

Flutter Prototype E-Commerce App

Flutter Prototype E-Commerce App

Flutter Prototype E-Commerce App

A cross-platform e-commerce application built with Flutter using the MVVM (Model-View-ViewModel) architecture pattern. This project demonstrates best practices for state management, navigation, data persistence, and interactive user experiences in Flutter.

You can find the project releases in the GitLab CI/CD Builds. GitLab

πŸ“± Project Overview

This application provides a complete e-commerce experience including:

  • Interactive 3D onboarding experience
  • User authentication with session management
  • Product browsing and catalog management
  • Shopping cart functionality with real-time updates
  • Order management and history tracking

πŸ—οΈ Architecture

The project follows the MVVM (Model-View-ViewModel) architecture pattern:

  • Models: Data structures representing core business logic
  • Views: UI components that display data to the user
  • ViewModels: Classes that handle business logic and state management

This separation ensures maintainable code organization, testability, and scalability.

πŸ“‚ Project Structure

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
lib/
β”œβ”€β”€ main.dart                # Entry point of the application
β”œβ”€β”€ models/                  # Data models
β”‚   β”œβ”€β”€ cart_model.dart      # Shopping cart item model
β”‚   β”œβ”€β”€ onboarding_model.dart# Onboarding screen model
β”‚   β”œβ”€β”€ order_model.dart     # Order data model
β”‚   β”œβ”€β”€ product_model.dart   # Product data model
β”‚   └── user_model.dart      # User data model
β”œβ”€β”€ services/                # Service classes
β”‚   └── app_preferences.dart # Handles app preferences and local storage
β”œβ”€β”€ view_models/             # ViewModels (State management)
β”‚   β”œβ”€β”€ auth_view_model.dart        # Authentication logic
β”‚   β”œβ”€β”€ cart_view_model.dart        # Shopping cart management
β”‚   β”œβ”€β”€ navigation_view_model.dart  # Navigation state management
β”‚   β”œβ”€β”€ onboarding_view_model.dart  # Onboarding flow management
β”‚   β”œβ”€β”€ order_view_model.dart       # Order management
β”‚   └── product_view_model.dart     # Product data management
└── views/                   # UI components
    β”œβ”€β”€ cart_view.dart       # Shopping cart screen
    β”œβ”€β”€ home_view.dart       # Home screen
    β”œβ”€β”€ login_view.dart      # Authentication screen
    β”œβ”€β”€ main_layout.dart     # Main application layout
    β”œβ”€β”€ onboarding_view.dart # Onboarding screens
    β”œβ”€β”€ orders_view.dart     # Order history screen
    β”œβ”€β”€ product_view.dart    # Product details screen
    └── software_view.dart   # Additional features screen

✨ Key Features

πŸ” Authentication

  • User login with credential validation
  • Session persistence using SharedPreferences
  • Automatic login for returning users
  • Secure logout functionality

πŸš€ Interactive 3D Onboarding

  • Multi-step onboarding process with smooth transitions
  • Interactive 3D model rendering using flutter_cube
  • Custom animations for camera movement and object rotation
  • Gradient background colors that transition between screens
  • Skip functionality for returning users
  • Progress tracking with animated indicators

Technical Implementation:

  • Custom animation controllers for coordinated animations
  • Vector3 interpolation for smooth camera movements
  • Optimized rendering with RepaintBoundary
  • Memory-efficient vector object reuse
  • Asynchronous 3D model loading

πŸ“¦ Product Management

  • Product listing with images and details
  • Mock API integration with simulated network requests
  • Loading state management
  • Error handling for failed network requests

πŸ›’ Shopping Cart

  • Add, remove, and update product quantities
  • Real-time total calculation
  • Item count tracking
  • Empty state handling
  • Persistent cart between sessions

πŸ“‹ Order Management

  • Order placement with cart validation
  • Order history tracking
  • Order status updates
  • Mock API for demonstration purposes

🧭 Navigation

  • Tab-based navigation with state preservation
  • Conditional navigation based on user authentication status
  • Deep linking support
  • Navigation state management through Provider

🎨 UI/UX Features

Theme and Styling

  • Material Design 3 implementation
  • Custom color schemes
  • Consistent typography
  • Responsive layouts for different screen sizes

Animations

  • Custom page transitions
  • Loading animations
  • Interactive UI elements
  • 3D model rotations and camera movements

Accessibility

  • Semantic labels for screen readers
  • Sufficient contrast ratios
  • Touch target sizing

πŸ”§ State Management

This project uses Provider for state management, demonstrating:

  • ChangeNotifier implementation
  • Provider scoping
  • Consumer pattern
  • MultiProvider for multiple data sources
  • Efficient rebuilds with selective listeners

🧩 Dependencies

Core Dependencies

  • flutter: Core Flutter framework
  • provider: State management solution
  • shared_preferences: Local data persistence

UI and Animation

  • flutter_cube: 3D model rendering
  • animations: Additional animation capabilities

Utils

  • intl: Internationalization and formatting

πŸš€ Getting Started

Prerequisites

  • Flutter SDK (2.0.0 or higher)
  • Dart SDK (2.12.0 or higher)
  • Android Studio / VS Code with Flutter extensions

Installation

  1. Clone the repository:
    1
    
    git clone https://github.com/yourusername/flutter_ecommerce_app.git
    
  2. Navigate to the project directory:
    1
    
    cd flutter_ecommerce_app
    
  3. Install dependencies:
    1
    
    flutter pub get
    
  4. Run the app:
    1
    
    flutter run
    

πŸ“± Usage

Authentication

Use the following credentials to log in:

  • Username: admin
  • Password: password

Onboarding

The onboarding flow showcases:

  • 5 sequential screens with unique information
  • Interactive 3D model that responds to transitions
  • Different camera angles for each screen
  • Smooth color transitions between screens
  • Navigation controls (next, previous, skip)

The onboarding flow will be shown on first app launch. You can reset it from the settings menu.

Development Notes

  • The app uses mock data for products and orders
  • Network requests are simulated with delays to demonstrate loading states
  • Shared preferences are used to persist user session and app state

πŸ§ͺ Testing

Unit Tests

Run unit tests with:

1
flutter test

Integration Tests

Run integration tests with:

1
flutter test integration_test

πŸ“š Code Examples

Implementing a ViewModel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class ProductViewModel extends ChangeNotifier {
  List<ProductModel> _products = [];
  bool _isLoading = false;
  String _errorMessage = '';

  List<ProductModel> get products => _products;
  bool get isLoading => _isLoading;
  String get errorMessage => _errorMessage;

  Future<void> fetchProducts() async {
    _isLoading = true;
    notifyListeners();
    
    try {
      // API call logic
      _errorMessage = '';
    } catch (e) {
      _errorMessage = 'Failed to fetch products: ${e.toString()}';
    }

    _isLoading = false;
    notifyListeners();
  }
}

Using SharedPreferences

1
2
3
4
5
6
7
8
9
// Check if first launch
bool isFirstLaunch() {
  return _preferences.getBool(_isFirstLaunchKey) ?? true;
}

// Set first launch complete
Future<void> setFirstLaunchComplete() async {
  await _preferences.setBool(_isFirstLaunchKey, false);
}

πŸ›£οΈ Roadmap

Future enhancements planned for this application:

  • Firebase integration for backend services
  • User profile management
  • Product search and filtering
  • Payment gateway integration
  • Push notifications
  • Theme customization
  • Localization support
This post is licensed under CC BY 4.0 by the author.