initial commit: push everything
This commit is contained in:
32
lib/providers/summary/riderweeklykms.dart
Normal file
32
lib/providers/summary/riderweeklykms.dart
Normal file
@@ -0,0 +1,32 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:nearle/Models/summary/riderweeklykms.dart';
|
||||
import 'package:nearle/controllers/riderkm.dart';
|
||||
|
||||
|
||||
class RiderWeeklyKmProvider extends ChangeNotifier {
|
||||
final RiderWeeklyKmController _controller = RiderWeeklyKmController();
|
||||
|
||||
bool isLoading = false;
|
||||
String? error;
|
||||
List<RiderWeeklyKms> kmsList = [];
|
||||
double totalKms = 0.0;
|
||||
|
||||
Future<void> fetchRiderWeeklyKms(int userId) async {
|
||||
isLoading = true;
|
||||
error = null;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
final result = await _controller.getRiderWeeklyKms(userId);
|
||||
kmsList = result['details'];
|
||||
totalKms = result['total_kms'];
|
||||
} catch (e) {
|
||||
error = e.toString();
|
||||
}
|
||||
|
||||
isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
33
lib/providers/summary/summary.dart
Normal file
33
lib/providers/summary/summary.dart
Normal file
@@ -0,0 +1,33 @@
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:nearle/models/summary/deliverystats.dart';
|
||||
import 'package:nearle/views/helpers/constants/apiconstants.dart';
|
||||
|
||||
class SummaryProvider {
|
||||
final String baseUrl = ApiConstants.summaryApiLive;
|
||||
|
||||
Future<DeliveryStats?> fetchSummaryStats(int userId) async {
|
||||
final url = Uri.parse('$baseUrl/getdeliverystats?userid=$userId');
|
||||
|
||||
try {
|
||||
print(url);
|
||||
final response = await http.get(url);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final decoded = jsonDecode(response.body);
|
||||
if (decoded['status'] == true && decoded['data'] != null) {
|
||||
return DeliveryStats.fromJson(decoded['data']);
|
||||
} else {
|
||||
print('API returned false status: ${decoded['message']}');
|
||||
}
|
||||
} else {
|
||||
print('something went wrong');
|
||||
}
|
||||
} catch (e) {
|
||||
print('something went wrong');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user