This is a sample E-commerce Flutter application built using the BLoC architecture. The app demonstrates the use of various Flutter features, including state management, secure storage, and local database (Drift).
- Authentication: Login and Signup functionalities with secure token storage.
- Product Listing: Displays products from a remote API and allows users to view detailed information.
- Shopping Cart: Manage the shopping cart and interact with products.
- Local Storage: Stores user data securely and persists data using Drift database.
First, clone this repository to your local machine:
git clone https://github.com/tamimsoft/E-commerce-BLoC.git
cd E-commerce-BLoCThis project uses Flutter 3.27.3. You can manage this version with FVM (Flutter Version Manager).
-
Install FVM if you haven't already:
dart pub global activate fvm
-
Install the required Flutter version for the project:
fvm install 3.27.3
-
Use the specified Flutter version for the project:
fvm use 3.27.3
Make sure to install the project dependencies:
flutter pub getOnce all the dependencies are installed and configurations are set, you can run the app using:
flutter runThe project follows the BLoC pattern and is organized into the following key folders:
- core/: Contains core services like API handling, secure storage, Drift database setup.
- common/: Holds reusable widgets and data models.
- features/: Contains feature-specific functionality such as Authentication, Home, and Cart.
- models/: Shared data models used across the app.
| Login Screen | Signup Screen | OTP Screen |
|---|---|---|
| Home Screen | Category Screen | Product List Screen | Product Details Screen |
|---|---|---|---|
| Favourite List Screen | Checkout Screen | Cart List Screen |
|---|---|---|
This app fetches product data and interacts with a sample API. You can customize the API endpoints in the ApiConstants class under core/constants/api_constants.dart.
Here is an example of a sample endpoint for fetching products:
Future<List<ProductModel>> getProducts() async {
final response = await http.get(Uri.parse('$baseUrl/products'));
if (response.statusCode == 200) {
final List<dynamic> json = jsonDecode(response.body);
return json.map((e) => ProductModel.fromJson(e)).toList();
} else {
throw Exception('Failed to load products');
}
}Make sure to replace the baseUrl with your actual API base URL.
For local data persistence, the app uses Drift (formerly known as moor). You can find the Drift setup in core/services/database/ and customize it according to your requirements.
class Products extends Table {
IntColumn get id => integer().autoIncrement()();
TextColumn get name => text().withLength(min: 1, max: 50)();
RealColumn get price => real()();
TextColumn get imageUrl => text().nullable()();
}