- Fix deprecated @ignore in json_serializable models (appState, yourLocation) - Fix empty catch blocks in compassMapPlugin, globalFiresBottomStats, locationUtils - Fix no_logic_in_create_state in firesApp, markdownPage, slider - Fix use_build_context_synchronously in fireAlert - Fix only_throw_errors in firesApi (8 instances) - Exclude generated .g.dart files from analysis - Update deprecated nullable: false to @JsonSerializable() Build: APK generated successfully, 0 errors, 0 warnings
122 lines
4.9 KiB
Dart
122 lines
4.9 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:comunes_flutter/comunes_flutter.dart';
|
|
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 '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 <YourLocation>[],
|
|
this.fireNotifications = const <FireNotification>[],
|
|
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 <Polyline>[],
|
|
this.fireMapState = const FireMapState.initial()});
|
|
|
|
factory AppState.fromJson(Map<String, dynamic> 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<YourLocation> yourLocations;
|
|
final List<FireNotification> fireNotifications;
|
|
@JsonKey(includeFromJson: false, includeToJson: false)
|
|
final List<Polyline> 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<YourLocation>? yourLocations,
|
|
List<FireNotification>? fireNotifications,
|
|
int? fireNotificationsUnread,
|
|
FireMapState? fireMapState,
|
|
List<Polyline>? 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<void> 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);
|