server_version.model.dart 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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) =>
  44. ServerVersion.fromMap(json.decode(source));
  45. @override
  46. String toString() {
  47. return 'ServerVersion(major: $major, minor: $minor, patch: $patch, build: $build)';
  48. }
  49. @override
  50. bool operator ==(Object other) {
  51. if (identical(this, other)) return true;
  52. return other is ServerVersion &&
  53. other.major == major &&
  54. other.minor == minor &&
  55. other.patch == patch &&
  56. other.build == build;
  57. }
  58. @override
  59. int get hashCode {
  60. return major.hashCode ^ minor.hashCode ^ patch.hashCode ^ build.hashCode;
  61. }
  62. }