connect with backend
This commit is contained in:
45
lib/providers/mark_list_provider.dart
Normal file
45
lib/providers/mark_list_provider.dart
Normal file
@@ -0,0 +1,45 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user