server_version.model.dart 1.5 KB

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