Initial commit for complete UI
This commit is contained in:
52
lib/provider/shop_provider.dart
Normal file
52
lib/provider/shop_provider.dart
Normal file
@@ -0,0 +1,52 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import '../models/shop_model.dart';
|
||||
|
||||
class ShopProvider with ChangeNotifier {
|
||||
ShopModel? _shop;
|
||||
ShopModel? get shop => _shop;
|
||||
|
||||
final String _boxName = 'shopBox';
|
||||
|
||||
ShopProvider() {
|
||||
_loadOrCreateDummyShop();
|
||||
}
|
||||
|
||||
void _loadOrCreateDummyShop() async {
|
||||
final box = await Hive.openBox<ShopModel>(_boxName);
|
||||
|
||||
if (box.isNotEmpty) {
|
||||
_shop = box.getAt(0);
|
||||
} else {
|
||||
// Dummy data
|
||||
_shop = ShopModel(
|
||||
id: '1',
|
||||
shopName: "Omkara Car Wash Center",
|
||||
email: "omkara@gmail.com",
|
||||
mobile: "8617019854",
|
||||
image: "assets/images/shop_image.jpg",
|
||||
address: "Bidhannagar, Kolkata, pin-700017",
|
||||
);
|
||||
await box.add(_shop!);
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> setShop(ShopModel shop) async {
|
||||
_shop = shop;
|
||||
notifyListeners();
|
||||
|
||||
final box = await Hive.openBox<ShopModel>(_boxName);
|
||||
await box.clear(); // Keep only one shop
|
||||
await box.add(shop);
|
||||
}
|
||||
|
||||
Future<void> logout() async {
|
||||
_shop = null;
|
||||
notifyListeners();
|
||||
|
||||
final box = await Hive.openBox<ShopModel>(_boxName);
|
||||
await box.clear();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user