import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:latlong2/latlong.dart'; import 'package:meta/meta.dart'; import '../utils/widget_utils.dart'; import 'fireMapState.dart'; import 'fireNotification.dart'; import 'user.dart'; import 'yourLocation.dart'; export 'fireMapState.dart'; part 'appState.g.dart'; @immutable @JsonSerializable() class AppState { const AppState( {this.yourLocations = const [], this.fireNotifications = const [], this.fireNotificationsUnread = 0, this.user = const User.initial(), this.isLoading = false, this.isLoaded = false, this.error = '', this.gmapKey = '', this.firesApiKey = '', this.firesApiUrl = '', this.serverUrl = '', this.monitoredAreas = const [], this.fireMapState = const FireMapState.initial()}); factory AppState.fromJson(Map json) => _$AppStateFromJson(json); final bool isLoading; @JsonKey(includeFromJson: false, includeToJson: false) final bool isLoaded; @JsonKey(includeFromJson: false, includeToJson: false) final String error; @JsonKey(includeFromJson: false, includeToJson: false) final User user; @JsonKey(includeFromJson: false, includeToJson: false) final String gmapKey; @JsonKey(includeFromJson: false, includeToJson: false) final String serverUrl; @JsonKey(includeFromJson: false, includeToJson: false) final String firesApiKey; @JsonKey(includeFromJson: false, includeToJson: false) final String firesApiUrl; final List yourLocations; final List fireNotifications; @JsonKey(includeFromJson: false, includeToJson: false) final List monitoredAreas; @JsonKey(includeFromJson: false, includeToJson: false) final int fireNotificationsUnread; @JsonKey(includeFromJson: false, includeToJson: false) final FireMapState fireMapState; AppState copyWith( {bool? isLoading, bool? isLoaded, User? user, String? error, String? gmapKey, String? firesApiKey, String? serverUrl, String? firesApiUrl, List? yourLocations, List? fireNotifications, int? fireNotificationsUnread, FireMapState? fireMapState, List? monitoredAreas}) { return AppState( isLoading: isLoading ?? this.isLoading, isLoaded: isLoaded ?? this.isLoaded, user: user ?? this.user, error: error ?? this.error, gmapKey: gmapKey ?? this.gmapKey, firesApiKey: firesApiKey ?? this.firesApiKey, firesApiUrl: firesApiUrl ?? this.firesApiUrl, serverUrl: serverUrl ?? this.serverUrl, yourLocations: yourLocations ?? this.yourLocations, fireNotifications: fireNotifications ?? this.fireNotifications, fireNotificationsUnread: fireNotificationsUnread ?? this.fireNotificationsUnread, monitoredAreas: monitoredAreas ?? this.monitoredAreas, fireMapState: fireMapState ?? this.fireMapState); } @override String toString() { return 'AppState{\nuser: $user\nisLoading: $isLoading\nisLoaded: $isLoaded\napiKey: ${ellipse(firesApiKey, 8)}\napiUrl: $firesApiUrl\nserverUrl: $serverUrl\nfireMapState: $fireMapState\nyourLocations count: ${yourLocations.length}\nunread notif: $fireNotificationsUnread\nfireNotifications: $fireNotifications\nyourLocations: $yourLocations}'; } } typedef AddYourLocationFunction = void Function(YourLocation loc); typedef DeleteYourLocationFunction = void Function(YourLocation loc); typedef OnRefreshYourLocationsFunction = void Function( Completer callback); typedef ToggleSubscriptionFunction = void Function(YourLocation loc); typedef OnLocationTapFunction = void Function(YourLocation loc); typedef OnSubscribeFunction = void Function(YourLocation loc); typedef OnSubscribeDistanceChangeFunction = void Function(YourLocation loc); typedef OnUnSubscribeFunction = void Function(YourLocation loc); typedef OnSubscribeConfirmedFunction = void Function(YourLocation loc); typedef OnLocationEdit = void Function(YourLocation loc); typedef OnLocationEditing = void Function(YourLocation loc); typedef OnLocationEditConfirm = void Function(YourLocation loc); typedef OnLocationEditCancel = void Function(YourLocation loc); typedef TapFireNotificationFunction = void Function(FireNotification notif); typedef OnFirePressedInMap = void Function( LatLng latLng, DateTime when, String source); // typedef void OnReceivedFireNotificationFunction(FireNotification notif); typedef DeleteFireNotificationFunction = void Function(FireNotification notif); typedef DeleteAllFireNotificationFunction = void Function(); // unused // typedef void UpdateYourLocationFunction(ObjectId id, YourLocation loc);