38 lines
1.0 KiB
Dart
38 lines
1.0 KiB
Dart
|
|
||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||
|
import 'package:medcify/network/api_provider.dart';
|
||
|
import 'package:medcify/storage/storage.dart';
|
||
|
|
||
|
import '../../../models/banner_item.dart';
|
||
|
|
||
|
abstract class HomeState{}
|
||
|
|
||
|
class HomeInitial extends HomeState{}
|
||
|
class HomeLoading extends HomeState{}
|
||
|
class HomeSuccess extends HomeState{}
|
||
|
|
||
|
class HomeCubit extends Cubit<HomeState> {
|
||
|
HomeCubit() : super(HomeInitial());
|
||
|
List<BannerItem> banners = [];
|
||
|
dynamic ordersCount = 0;
|
||
|
dynamic salesCount = 0;
|
||
|
dynamic visitorsCount = 0;
|
||
|
String url = "";
|
||
|
String storeName = "";
|
||
|
int notificationCount = 0;
|
||
|
|
||
|
Future<void> fetchHomeData() async{
|
||
|
emit(HomeLoading());
|
||
|
final response = await ApiProvider.instance.fetchHomeData();
|
||
|
banners = response[0].banners;
|
||
|
ordersCount = response[1].count;
|
||
|
salesCount = response[2].count;
|
||
|
visitorsCount = response[3].count;
|
||
|
notificationCount = response[5].count;
|
||
|
url = response[4].url;
|
||
|
storeName = response[4].name;
|
||
|
if(url.isNotEmpty)Storage.instance.setStoreUrl(url);
|
||
|
emit(HomeSuccess());
|
||
|
}
|
||
|
|
||
|
}
|