Skip to content

jahids/E-commerce-flutter

Repository files navigation

Flutter GetX Production App

A production-level Flutter application built with GetX state management, featuring a clean architecture and industry-standard folder structure.

πŸš€ Features

  • GetX State Management - Reactive state management with controllers and bindings
  • Clean Architecture - Modular folder structure following industry standards
  • JSONPlaceholder API Integration - Full CRUD operations on posts
  • Reactive UI - Automatic UI updates with Obx() and Rx variables
  • Navigation - GetX route management with transitions
  • Error Handling - Comprehensive error handling and loading states
  • Responsive Design - Material Design 3 with modern UI components

πŸ“± Screens

  1. Home Screen - Displays list of posts with pull-to-refresh
  2. Detail Screen - Shows individual post details with edit/delete functionality

πŸ—οΈ Project Structure

lib/
β”œβ”€β”€ main.dart                    # App entry point with GetX initialization
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”œβ”€β”€ app_pages.dart       # GetX route configuration with bindings
β”‚   β”‚   └── app_routes.dart      # Route constants
β”‚   β”‚
β”‚   β”œβ”€β”€ modules/
β”‚   β”‚   β”œβ”€β”€ home/
β”‚   β”‚   β”‚   β”œβ”€β”€ home_view.dart   # Home screen UI
β”‚   β”‚   β”‚   β”œβ”€β”€ home_controller.dart # Home business logic
β”‚   β”‚   β”‚   └── home_binding.dart    # Home dependencies
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ detail/
β”‚   β”‚   β”‚   β”œβ”€β”€ detail_view.dart     # Detail screen UI
β”‚   β”‚   β”‚   β”œβ”€β”€ detail_controller.dart # Detail business logic
β”‚   β”‚   β”‚   └── detail_binding.dart    # Detail dependencies
β”‚   β”‚
β”‚   β”œβ”€β”€ data/
β”‚   β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”‚   └── post_model.dart      # Post data model with JSON serialization
β”‚   β”‚   └── providers/
β”‚   β”‚       └── api_provider.dart    # HTTP API client for JSONPlaceholder
β”‚   β”‚
β”‚   └── widgets/
β”‚       └── custom_button.dart       # Reusable button component

πŸ› οΈ Technologies Used

  • Flutter - UI framework
  • GetX - State management, navigation, and dependency injection
  • HTTP - API communication
  • JSON Serialization - Data model serialization
  • Material Design 3 - Modern UI components

πŸ“‹ API Endpoints

The app uses JSONPlaceholder for testing:

  • GET /posts - Fetch all posts
  • GET /posts/{id} - Fetch single post
  • POST /posts - Create new post
  • PUT /posts/{id} - Update existing post
  • DELETE /posts/{id} - Delete post

πŸš€ Getting Started

Prerequisites

  • Flutter SDK (latest stable version)
  • Dart SDK
  • Android Studio / VS Code

Installation

  1. Clone the repository

    git clone <repository-url>
    cd flutter_app
  2. Install dependencies

    flutter pub get
  3. Generate JSON serialization code

    flutter packages pub run build_runner build
  4. Run the app

    flutter run

🎯 How It Works

State Management with GetX

The app uses GetX for reactive state management:

// Observable variables automatically update UI
final RxList<Post> posts = <Post>[].obs;
final RxBool isLoading = false.obs;

// UI automatically rebuilds when data changes
Obx(() => ListView.builder(
  itemCount: controller.posts.length,
  itemBuilder: (context, index) => PostCard(controller.posts[index]),
))

Dependency Injection

Controllers are injected using GetX bindings:

class HomeBinding extends Bindings {
  @override
  void dependencies() {
    Get.lazyPut<HomeController>(() => HomeController());
  }
}

Navigation

GetX handles navigation with route management:

// Navigate to detail page with data
Get.toNamed('/detail', arguments: post);

// Go back
Get.back();

πŸ“± App Features

Home Screen

  • Posts List - Displays all posts from API
  • Pull to Refresh - Refresh posts list
  • Create Post - Add new post (FAB)
  • Delete Post - Remove posts with confirmation
  • Navigate to Detail - Tap post to view details

Detail Screen

  • Post Details - Full post information display
  • Edit Post - Update post title and content
  • Delete Post - Remove post with confirmation
  • Back Navigation - Return to home screen

πŸ”§ Architecture Benefits

1. Separation of Concerns

  • Views - Handle UI only
  • Controllers - Manage business logic and state
  • Models - Define data structure
  • Providers - Handle external data sources

2. Reactive Programming

  • Automatic UI updates when data changes
  • No manual setState() calls needed
  • Efficient memory usage

3. Dependency Injection

  • Controllers are automatically injected
  • Easy to test and mock dependencies
  • Lazy loading for better performance

4. Route Management

  • Type-safe navigation
  • Automatic route generation
  • Transition animations

πŸ§ͺ Testing

The app is structured for easy testing:

// Test controller logic
class HomeControllerTest {
  test('should fetch posts from API', () async {
    final controller = HomeController();
    await controller.fetchPosts();
    expect(controller.posts.length, greaterThan(0));
  });
}

πŸ“¦ Dependencies

dependencies:
  flutter:
    sdk: flutter
  get: ^4.6.6          # State management
  http: ^1.2.0         # HTTP client
  json_annotation: ^4.9.0  # JSON serialization

dev_dependencies:
  json_serializable: ^6.8.0  # Code generation
  build_runner: ^2.4.13      # Build tools

πŸš€ Production Ready Features

  • βœ… Null Safety - Full Dart null safety implementation
  • βœ… Error Handling - Comprehensive error handling and user feedback
  • βœ… Loading States - Proper loading indicators
  • βœ… Responsive Design - Works on different screen sizes
  • βœ… Clean Code - Well-documented and maintainable code
  • βœ… Performance - Efficient state management and lazy loading
  • βœ… Scalability - Modular architecture for easy expansion

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License.

πŸ†˜ Support

For support and questions:

  • Check the GetX documentation
  • Review the code comments for implementation details
  • Open an issue in the repository

Built with ❀️ using Flutter and GetX

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors