Remove the external comunes-flutter library dependency and replace all its components with local implementations: - Utility functions: Created lib/utils/widget_utils.dart with compactWidgets() and ellipse() functions, replacing the comunes-flutter helpers with modern Dart null-safety patterns (whereType instead of where(notNull)) - Secret loader: Inlined as lib/utils/secret_loader.dart for loading JSON config - Layout widgets: Replaced CenteredRow/CenteredColumn with standard Row/Column with MainAxisAlignment.center - Intro screens: Copied AppIntroPage and MaterialAppWithIntro locally in lib/widgets/ with cleaned-up deprecated code patterns - Button widget: Created lib/widgets/rounded_btn.dart for the RoundedBtn used in activeFires.dart Changes span 20 files: - 5 new utility/widget files created - Updated imports in 15 files - Removed path dependency from pubspec.yaml - All functionality preserved, build verified with flutter pub get Impact: - Removes external dependency, simplifying project structure - Modern Dart patterns (proper null-safety) - Better code clarity with explicit widget properties - Easier onboarding (no 'what is comunes-flutter?' questions)
122 lines
4.8 KiB
Dart
122 lines
4.8 KiB
Dart
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 <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);
|