connect with backend
This commit is contained in:
39
lib/providers/dashboard_provider.dart
Normal file
39
lib/providers/dashboard_provider.dart
Normal file
@@ -0,0 +1,39 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../services/dashboard_service.dart';
|
||||
|
||||
class DashboardProvider extends ChangeNotifier {
|
||||
DashboardService? _service;
|
||||
|
||||
bool loading = false;
|
||||
|
||||
int activeOrders = 0;
|
||||
int inTransitOrders = 0;
|
||||
int deliveredOrders = 0;
|
||||
String totalValue = "0";
|
||||
double totalRaw = 0;
|
||||
|
||||
void init(BuildContext context) {
|
||||
_service = DashboardService(context);
|
||||
}
|
||||
|
||||
Future<void> loadSummary(BuildContext context) async {
|
||||
loading = true;
|
||||
notifyListeners();
|
||||
|
||||
_service ??= DashboardService(context);
|
||||
final res = await _service!.getSummary();
|
||||
|
||||
if (res['status'] == true) {
|
||||
final s = res['summary'];
|
||||
|
||||
activeOrders = s['active_orders'] ?? 0;
|
||||
inTransitOrders = s['in_transit_orders'] ?? 0;
|
||||
deliveredOrders = s['delivered_orders'] ?? 0;
|
||||
totalValue = s['total_value']?.toString() ?? "0";
|
||||
totalRaw = double.tryParse(s['total_raw'].toString()) ?? 0;
|
||||
}
|
||||
|
||||
loading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user