34 lines
864 B
Dart
34 lines
864 B
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../../model/location.dart';
|
|
import '../../model/repositories/interfaces/location_repository.dart';
|
|
|
|
class LocationController extends ChangeNotifier {
|
|
LocationController(LocationRepository repository) : _repository = repository {
|
|
_loadLocations();
|
|
}
|
|
|
|
final LocationRepository _repository;
|
|
|
|
final List<Location> _locations = [];
|
|
|
|
Future<void> addLocation(Location location) {
|
|
_locations.add(location);
|
|
notifyListeners();
|
|
return _repository.createLocation(location);
|
|
}
|
|
|
|
Future<void> deleteLocation(Location location) {
|
|
_locations.remove(location);
|
|
notifyListeners();
|
|
return _repository.deleteLocation(location);
|
|
}
|
|
|
|
Future<void> _loadLocations() {
|
|
_locations.clear();
|
|
return _repository.loadLocations().then(
|
|
(value) => _locations.addAll(value),
|
|
);
|
|
}
|
|
}
|