Files
kent_logistics_app/lib/providers/mark_list_provider.dart

46 lines
1013 B
Dart
Raw Normal View History

2025-12-03 11:57:05 +05:30
import 'package:flutter/material.dart';
import '../services/mark_list_service.dart';
class MarkListProvider extends ChangeNotifier {
MarkListService? _service;
List<dynamic> marks = [];
bool loading = false;
void init(BuildContext context) {
_service = MarkListService(context);
}
Future<void> loadMarks(BuildContext context) async {
loading = true;
notifyListeners();
_service ??= MarkListService(context);
final res = await _service!.getMarks();
if (res['success'] == true) {
marks = res['data'] ?? [];
}
loading = false;
notifyListeners();
}
Future<Map<String, dynamic>> addMark(BuildContext context, String mark, String origin, String destination) async {
_service ??= MarkListService(context);
final res = await _service!.addMark({
"mark_no": mark,
"origin": origin,
"destination": destination
});
if (res['success'] == true) {
await loadMarks(context); // refresh list
}
return res;
}
}