46 lines
1013 B
Dart
46 lines
1013 B
Dart
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;
|
|
}
|
|
}
|