ObjectBox

This commit is contained in:
Sven committed 2025-10-23 11:28:03 +02:00
1 parent e548f62bde
commit f8317be627
60 files changed
+2367 -15049

No files matched your search

+67 -29
View File
@@ -1,57 +1,95 @@
import 'package:isar/isar.dart';
import 'package:json_annotation/json_annotation.dart';
import 'dart:convert';
import 'package:objectbox/objectbox.dart';
part 'rank.g.dart';
@collection
@JsonSerializable()
@Entity()
class Ranking {
@JsonValue(0)
late Id? id = Isar.autoIncrement;
@Id()
int id = 0;
@JsonKey(name: "ranking")
late List<Rank> ranks;
// Store ranks as JSON string
String ranksJson = '[]';
@Transient()
List<Rank> get ranks {
final List<dynamic> decoded = jsonDecode(ranksJson);
return decoded.map((e) => Rank.fromJson(e as Map<String, dynamic>)).toList();
}
set ranks(List<Rank> value) {
ranksJson = jsonEncode(value.map((e) => e.toJson()).toList());
}
Ranking();
factory Ranking.fromJson(Map<String, dynamic> json) => _$RankingFromJson(json);
factory Ranking.fromJson(Map<String, dynamic> json) {
final ranking = Ranking();
ranking.id = json['id'] as int? ?? 0;
ranking.ranks = (json['ranking'] as List<dynamic>)
.map((e) => Rank.fromJson(e as Map<String, dynamic>))
.toList();
return ranking;
}
Map<String, dynamic> toJson() => _$RankingToJson(this);
Map<String, dynamic> toJson() {
return {
'id': id,
'ranking': ranks.map((e) => e.toJson()).toList(),
};
}
}
@embedded
@JsonSerializable()
class Rank {
late int id;
late String zip;
String? area;
late List<Vehicle> vehicles;
Rank();
factory Rank.fromJson(Map<String, dynamic> json) => _$RankFromJson(json);
factory Rank.fromJson(Map<String, dynamic> json) {
final rank = Rank();
rank.id = json['id'] as int;
rank.zip = json['zip'] as String;
rank.area = json['area'] as String?;
rank.vehicles = (json['vehicles'] as List<dynamic>)
.map((e) => Vehicle.fromJson(e as Map<String, dynamic>))
.toList();
return rank;
}
Map<String, dynamic> toJson() => _$RankToJson(this);
Map<String, dynamic> toJson() {
return {
'id': id,
'zip': zip,
'area': area,
'vehicles': vehicles.map((e) => e.toJson()).toList(),
};
}
}
@embedded
@JsonSerializable()
class Vehicle {
late int id;
late int type;
late int? cnt;
@JsonKey(name: 'self', defaultValue: false)
late bool? self;
int? cnt;
bool? self;
Vehicle();
factory Vehicle.fromJson(Map<String, dynamic> json) => _$VehicleFromJson(json);
factory Vehicle.fromJson(Map<String, dynamic> json) {
final vehicle = Vehicle();
vehicle.id = json['id'] as int;
vehicle.type = json['type'] as int;
vehicle.cnt = json['cnt'] as int?;
vehicle.self = json['self'] as bool? ?? false;
return vehicle;
}
Map<String, dynamic> toJson() => _$VehicleToJson(this);
Map<String, dynamic> toJson() {
return {
'id': id,
'type': type,
'cnt': cnt,
'self': self,
};
}
}