server_info_state.model.dart 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import 'dart:convert';
  2. import 'package:immich_mobile/shared/models/mapbox_info.model.dart';
  3. import 'package:immich_mobile/shared/models/server_version.model.dart';
  4. class ServerInfoState {
  5. final MapboxInfo mapboxInfo;
  6. final ServerVersion serverVersion;
  7. final bool isVersionMismatch;
  8. final String versionMismatchErrorMessage;
  9. ServerInfoState({
  10. required this.mapboxInfo,
  11. required this.serverVersion,
  12. required this.isVersionMismatch,
  13. required this.versionMismatchErrorMessage,
  14. });
  15. ServerInfoState copyWith({
  16. MapboxInfo? mapboxInfo,
  17. ServerVersion? serverVersion,
  18. bool? isVersionMismatch,
  19. String? versionMismatchErrorMessage,
  20. }) {
  21. return ServerInfoState(
  22. mapboxInfo: mapboxInfo ?? this.mapboxInfo,
  23. serverVersion: serverVersion ?? this.serverVersion,
  24. isVersionMismatch: isVersionMismatch ?? this.isVersionMismatch,
  25. versionMismatchErrorMessage: versionMismatchErrorMessage ?? this.versionMismatchErrorMessage,
  26. );
  27. }
  28. Map<String, dynamic> toMap() {
  29. return {
  30. 'mapboxInfo': mapboxInfo.toMap(),
  31. 'serverVersion': serverVersion.toMap(),
  32. 'isVersionMismatch': isVersionMismatch,
  33. 'versionMismatchErrorMessage': versionMismatchErrorMessage,
  34. };
  35. }
  36. factory ServerInfoState.fromMap(Map<String, dynamic> map) {
  37. return ServerInfoState(
  38. mapboxInfo: MapboxInfo.fromMap(map['mapboxInfo']),
  39. serverVersion: ServerVersion.fromMap(map['serverVersion']),
  40. isVersionMismatch: map['isVersionMismatch'] ?? false,
  41. versionMismatchErrorMessage: map['versionMismatchErrorMessage'] ?? '',
  42. );
  43. }
  44. String toJson() => json.encode(toMap());
  45. factory ServerInfoState.fromJson(String source) => ServerInfoState.fromMap(json.decode(source));
  46. @override
  47. String toString() {
  48. return 'ServerInfoState(mapboxInfo: $mapboxInfo, serverVersion: $serverVersion, isVersionMismatch: $isVersionMismatch, versionMismatchErrorMessage: $versionMismatchErrorMessage)';
  49. }
  50. @override
  51. bool operator ==(Object other) {
  52. if (identical(this, other)) return true;
  53. return other is ServerInfoState &&
  54. other.mapboxInfo == mapboxInfo &&
  55. other.serverVersion == serverVersion &&
  56. other.isVersionMismatch == isVersionMismatch &&
  57. other.versionMismatchErrorMessage == versionMismatchErrorMessage;
  58. }
  59. @override
  60. int get hashCode {
  61. return mapboxInfo.hashCode ^
  62. serverVersion.hashCode ^
  63. isVersionMismatch.hashCode ^
  64. versionMismatchErrorMessage.hashCode;
  65. }
  66. }