27 lines
890 B
Dart
27 lines
890 B
Dart
|
|
||
|
|
||
|
import 'package:bloc/bloc.dart';
|
||
|
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
|
||
|
import 'package:ot_viewer_app/owntracks_api.dart';
|
||
|
|
||
|
class GlobalLocationStoreState {
|
||
|
final IMap<(String, String), Point> locations;
|
||
|
|
||
|
GlobalLocationStoreState({required this.locations});
|
||
|
|
||
|
@override
|
||
|
String toString() => 'GlobalLocationStoreState(locations: $locations)';
|
||
|
}
|
||
|
|
||
|
// Define the Cubit
|
||
|
class GlobalLocationStoreCubit extends Cubit<GlobalLocationStoreState> {
|
||
|
GlobalLocationStoreCubit() : super(GlobalLocationStoreState(locations: IMap(const {})));
|
||
|
|
||
|
// Function to update the points
|
||
|
void updatePoint(String user, String device, Point point) {
|
||
|
// Create a new map with the updated point
|
||
|
final updatedLocations = state.locations.add((user, device), point);
|
||
|
// Emit the new state
|
||
|
emit(GlobalLocationStoreState(locations: updatedLocations));
|
||
|
}
|
||
|
}
|