216 lines
7.5 KiB
Dart
216 lines
7.5 KiB
Dart
import 'package:uuid/uuid.dart';
|
|
import 'package:retail/features/products/data/models/product_model.dart';
|
|
import 'package:retail/features/categories/data/models/category_model.dart';
|
|
|
|
/// Seed data generator for testing and initial app setup
|
|
class SeedData {
|
|
static const _uuid = Uuid();
|
|
|
|
/// Generate sample categories
|
|
static List<CategoryModel> generateCategories() {
|
|
final now = DateTime.now();
|
|
|
|
return [
|
|
CategoryModel(
|
|
id: 'cat_electronics',
|
|
name: 'Electronics',
|
|
description: 'Electronic devices and accessories',
|
|
iconPath: 'devices',
|
|
color: '#2196F3', // Blue
|
|
productCount: 0,
|
|
createdAt: now.subtract(const Duration(days: 60)),
|
|
updatedAt: now.subtract(const Duration(days: 60)),
|
|
),
|
|
CategoryModel(
|
|
id: 'cat_appliances',
|
|
name: 'Home Appliances',
|
|
description: 'Kitchen and home appliances',
|
|
iconPath: 'kitchen',
|
|
color: '#4CAF50', // Green
|
|
productCount: 0,
|
|
createdAt: now.subtract(const Duration(days: 55)),
|
|
updatedAt: now.subtract(const Duration(days: 55)),
|
|
),
|
|
CategoryModel(
|
|
id: 'cat_sports',
|
|
name: 'Sports & Fitness',
|
|
description: 'Sports equipment and fitness gear',
|
|
iconPath: 'fitness_center',
|
|
color: '#FF9800', // Orange
|
|
productCount: 0,
|
|
createdAt: now.subtract(const Duration(days: 50)),
|
|
updatedAt: now.subtract(const Duration(days: 50)),
|
|
),
|
|
CategoryModel(
|
|
id: 'cat_fashion',
|
|
name: 'Fashion',
|
|
description: 'Clothing, shoes, and accessories',
|
|
iconPath: 'checkroom',
|
|
color: '#E91E63', // Pink
|
|
productCount: 0,
|
|
createdAt: now.subtract(const Duration(days: 45)),
|
|
updatedAt: now.subtract(const Duration(days: 45)),
|
|
),
|
|
CategoryModel(
|
|
id: 'cat_books',
|
|
name: 'Books & Media',
|
|
description: 'Books, magazines, and media',
|
|
iconPath: 'book',
|
|
color: '#9C27B0', // Purple
|
|
productCount: 0,
|
|
createdAt: now.subtract(const Duration(days: 40)),
|
|
updatedAt: now.subtract(const Duration(days: 40)),
|
|
),
|
|
];
|
|
}
|
|
|
|
/// Generate sample products
|
|
static List<ProductModel> generateProducts() {
|
|
final now = DateTime.now();
|
|
|
|
return [
|
|
// Electronics (3 products)
|
|
ProductModel(
|
|
id: 'prod_${_uuid.v4()}',
|
|
name: 'Wireless Headphones',
|
|
description: 'Premium noise-cancelling wireless headphones with 30-hour battery life',
|
|
price: 299.99,
|
|
imageUrl: 'https://picsum.photos/seed/headphones/400/400',
|
|
categoryId: 'cat_electronics',
|
|
stockQuantity: 25,
|
|
isAvailable: true,
|
|
createdAt: now.subtract(const Duration(days: 30)),
|
|
updatedAt: now.subtract(const Duration(days: 1)),
|
|
),
|
|
ProductModel(
|
|
id: 'prod_${_uuid.v4()}',
|
|
name: 'Smart Watch',
|
|
description: 'Fitness tracking smart watch with heart rate monitor and GPS',
|
|
price: 199.99,
|
|
imageUrl: 'https://picsum.photos/seed/smartwatch/400/400',
|
|
categoryId: 'cat_electronics',
|
|
stockQuantity: 15,
|
|
isAvailable: true,
|
|
createdAt: now.subtract(const Duration(days: 25)),
|
|
updatedAt: now.subtract(const Duration(days: 2)),
|
|
),
|
|
ProductModel(
|
|
id: 'prod_${_uuid.v4()}',
|
|
name: 'Laptop Stand',
|
|
description: 'Adjustable aluminum laptop stand with ergonomic design',
|
|
price: 39.99,
|
|
imageUrl: 'https://picsum.photos/seed/laptopstand/400/400',
|
|
categoryId: 'cat_electronics',
|
|
stockQuantity: 20,
|
|
isAvailable: true,
|
|
createdAt: now.subtract(const Duration(days: 20)),
|
|
updatedAt: now.subtract(const Duration(days: 1)),
|
|
),
|
|
|
|
// Home Appliances (2 products)
|
|
ProductModel(
|
|
id: 'prod_${_uuid.v4()}',
|
|
name: 'Coffee Maker',
|
|
description: 'Automatic drip coffee maker with programmable timer and thermal carafe',
|
|
price: 79.99,
|
|
imageUrl: 'https://picsum.photos/seed/coffeemaker/400/400',
|
|
categoryId: 'cat_appliances',
|
|
stockQuantity: 8,
|
|
isAvailable: true,
|
|
createdAt: now.subtract(const Duration(days: 18)),
|
|
updatedAt: now.subtract(const Duration(days: 3)),
|
|
),
|
|
ProductModel(
|
|
id: 'prod_${_uuid.v4()}',
|
|
name: 'Blender',
|
|
description: 'High-power 1000W blender perfect for smoothies and crushing ice',
|
|
price: 59.99,
|
|
imageUrl: 'https://picsum.photos/seed/blender/400/400',
|
|
categoryId: 'cat_appliances',
|
|
stockQuantity: 12,
|
|
isAvailable: true,
|
|
createdAt: now.subtract(const Duration(days: 15)),
|
|
updatedAt: now.subtract(const Duration(days: 2)),
|
|
),
|
|
|
|
// Sports & Fitness (3 products)
|
|
ProductModel(
|
|
id: 'prod_${_uuid.v4()}',
|
|
name: 'Yoga Mat',
|
|
description: 'Non-slip exercise yoga mat with carrying strap, 6mm thickness',
|
|
price: 29.99,
|
|
imageUrl: 'https://picsum.photos/seed/yogamat/400/400',
|
|
categoryId: 'cat_sports',
|
|
stockQuantity: 50,
|
|
isAvailable: true,
|
|
createdAt: now.subtract(const Duration(days: 12)),
|
|
updatedAt: now.subtract(const Duration(days: 1)),
|
|
),
|
|
ProductModel(
|
|
id: 'prod_${_uuid.v4()}',
|
|
name: 'Running Shoes',
|
|
description: 'Comfortable running shoes with responsive cushioning and breathable mesh',
|
|
price: 89.99,
|
|
imageUrl: 'https://picsum.photos/seed/runningshoes/400/400',
|
|
categoryId: 'cat_sports',
|
|
stockQuantity: 30,
|
|
isAvailable: true,
|
|
createdAt: now.subtract(const Duration(days: 10)),
|
|
updatedAt: now.subtract(const Duration(days: 2)),
|
|
),
|
|
ProductModel(
|
|
id: 'prod_${_uuid.v4()}',
|
|
name: 'Water Bottle',
|
|
description: 'Insulated stainless steel water bottle, 32oz capacity, keeps cold 24hrs',
|
|
price: 24.99,
|
|
imageUrl: 'https://picsum.photos/seed/waterbottle/400/400',
|
|
categoryId: 'cat_sports',
|
|
stockQuantity: 45,
|
|
isAvailable: true,
|
|
createdAt: now.subtract(const Duration(days: 8)),
|
|
updatedAt: now,
|
|
),
|
|
|
|
// Fashion (2 products)
|
|
ProductModel(
|
|
id: 'prod_${_uuid.v4()}',
|
|
name: 'Leather Backpack',
|
|
description: 'Premium leather backpack with laptop compartment and multiple pockets',
|
|
price: 129.99,
|
|
imageUrl: 'https://picsum.photos/seed/backpack/400/400',
|
|
categoryId: 'cat_fashion',
|
|
stockQuantity: 18,
|
|
isAvailable: true,
|
|
createdAt: now.subtract(const Duration(days: 7)),
|
|
updatedAt: now.subtract(const Duration(days: 1)),
|
|
),
|
|
ProductModel(
|
|
id: 'prod_${_uuid.v4()}',
|
|
name: 'Sunglasses',
|
|
description: 'UV protection polarized sunglasses with stylish design',
|
|
price: 49.99,
|
|
imageUrl: 'https://picsum.photos/seed/sunglasses/400/400',
|
|
categoryId: 'cat_fashion',
|
|
stockQuantity: 35,
|
|
isAvailable: true,
|
|
createdAt: now.subtract(const Duration(days: 5)),
|
|
updatedAt: now.subtract(const Duration(days: 1)),
|
|
),
|
|
];
|
|
}
|
|
|
|
/// Seed database with sample data
|
|
static Future<void> seedDatabase({
|
|
required Future<void> Function(List<CategoryModel>) saveCategories,
|
|
required Future<void> Function(List<ProductModel>) saveProducts,
|
|
}) async {
|
|
// Generate and save categories
|
|
final categories = generateCategories();
|
|
await saveCategories(categories);
|
|
|
|
// Generate and save products
|
|
final products = generateProducts();
|
|
await saveProducts(products);
|
|
}
|
|
}
|