Files
mileograph_flutter/lib/objects/objects.dart

288 lines
7.1 KiB
Dart

import 'package:flutter/material.dart';
class DestinationObject {
const DestinationObject(
this.label,
this.icon,
this.selectedIcon,
this.pageWidget,
);
final String label;
final Widget icon;
final Widget selectedIcon;
final Widget pageWidget;
}
class UserData {
const UserData(this.username, this.full_name, this.user_id, this.email);
final String user_id;
final String username;
final String full_name;
final String email;
}
class AuthenticatedUserData extends UserData {
const AuthenticatedUserData({
required String user_id,
required String username,
required String full_name,
required String email,
required this.access_token,
}) : super(username, full_name, user_id, email);
final String access_token;
}
class HomepageStats {
final double totalMileage;
final List<YearlyMileage> yearlyMileage;
final List<LocoSummary> topLocos;
final List<LeaderboardEntry> leaderboard;
final List<TripSummary> trips;
HomepageStats({
required this.totalMileage,
required this.yearlyMileage,
required this.topLocos,
required this.leaderboard,
required this.trips,
});
factory HomepageStats.fromJson(Map<String, dynamic> json) {
return HomepageStats(
totalMileage: (json['milage_data']['mileage'] as num).toDouble(),
yearlyMileage: (json['yearly_mileage'] as List)
.map((e) => YearlyMileage.fromJson(e))
.toList(),
topLocos: (json['top_locos'] as List)
.map((e) => LocoSummary.fromJson(e))
.toList(),
leaderboard: (json['leaderboard_data'] as List)
.map((e) => LeaderboardEntry.fromJson(e))
.toList(),
trips: (json['trip_data'] as List)
.map((e) => TripSummary.fromJson(e))
.toList(),
);
}
}
class YearlyMileage {
final int? year;
final double mileage;
YearlyMileage({this.year, required this.mileage});
factory YearlyMileage.fromJson(Map<String, dynamic> json) => YearlyMileage(
year: json['year'],
mileage: (json['mileage'] as num).toDouble(),
);
}
class Loco {
final int id;
final String type, number, locoClass;
final String? name, operator, notes, evn;
Loco({
required this.id,
required this.type,
required this.number,
required this.name,
required this.locoClass,
required this.operator,
this.notes,
this.evn,
});
factory Loco.fromJson(Map<String, dynamic> json) => Loco(
id: json['loco_id'],
type: json['loco_type'],
number: json['loco_number'],
name: json['loco_name'] ?? "",
locoClass: json['loco_class'],
operator: json['loco_operator'],
notes: json['loco_notes'],
evn: json['loco_evn'],
);
}
class LocoSummary extends Loco {
final double? mileage;
final int? journeys;
LocoSummary({
required int locoId,
required String locoType,
required String locoNumber,
required String locoName,
required String locoClass,
required String locoOperator,
String? locoNotes,
String? locoEvn,
this.mileage,
this.journeys,
}) : super(
id: locoId,
type: locoType,
number: locoNumber,
name: locoName,
locoClass: locoClass,
operator: locoOperator,
notes: locoNotes,
evn: locoEvn,
);
factory LocoSummary.fromJson(Map<String, dynamic> json) => LocoSummary(
locoId: json['loco_id'],
locoType: json['loco_type'],
locoNumber: json['loco_number'],
locoName: json['loco_name'] ?? "",
locoClass: json['loco_class'],
locoOperator: json['loco_operator'],
locoNotes: json['loco_notes'],
locoEvn: json['loco_evn'],
mileage: (json['loco_mileage'] as num?)?.toDouble() ?? 0,
journeys: json['loco_journeys'] ?? 0,
);
}
class LeaderboardEntry {
final String userId, username, userFullName;
final double mileage;
LeaderboardEntry({
required this.userId,
required this.username,
required this.userFullName,
required this.mileage,
});
factory LeaderboardEntry.fromJson(Map<String, dynamic> json) =>
LeaderboardEntry(
userId: json['user_id'],
username: json['username'],
userFullName: json['user_full_name'],
mileage: (json['mileage'] as num).toDouble(),
);
}
class TripSummary {
final int tripId;
final String tripName;
final double tripMileage;
TripSummary({
required this.tripId,
required this.tripName,
required this.tripMileage,
});
factory TripSummary.fromJson(Map<String, dynamic> json) => TripSummary(
tripId: json['trip_id'],
tripName: json['trip_name'],
tripMileage: (json['trip_mileage'] as num).toDouble(),
);
}
class Leg {
final int id, tripId, timezone, driving;
final String start, end, route, network, notes, headcode, user;
final DateTime beginTime;
final double mileage;
final List<Loco> locos;
Leg({
required this.id,
required this.tripId,
required this.start,
required this.end,
required this.beginTime,
required this.timezone,
required this.network,
required this.route,
required this.mileage,
required this.notes,
required this.headcode,
required this.driving,
required this.user,
required this.locos,
});
factory Leg.fromJson(Map<String, dynamic> json) => Leg(
id: json['leg_id'],
tripId: json['leg_trip'] ?? 0,
start: json['leg_start'],
end: json['leg_end'],
beginTime: DateTime.parse(json['leg_begin_time']),
timezone: (json['leg_timezone'] as num).toInt(),
network: json['leg_network'] ?? "",
route: json['leg_route'],
mileage: (json['leg_mileage'] as num).toDouble(),
notes: json['leg_notes'] ?? "",
headcode: json['leg_headcode'] ?? "",
driving: json['leg_driving'],
user: json['leg_user'],
locos: (json['locos'] as List)
.map((e) => Loco.fromJson(e as Map<String, dynamic>))
.toList(),
);
}
class RouteError {
final String error;
final String msg;
RouteError({required this.error, required this.msg});
factory RouteError.fromJson(Map<String, dynamic> json) {
return RouteError(error: json["error"], msg: json["msg"]);
}
}
class RouteResult {
final List<String> inputRoute;
final List<String> calculatedRoute;
final List<double> costs;
final double distance;
RouteResult({
required this.inputRoute,
required this.calculatedRoute,
required this.costs,
required this.distance,
});
factory RouteResult.fromJson(Map<String, dynamic> json) {
return RouteResult(
inputRoute: List<String>.from(json['input_route']),
calculatedRoute: List<String>.from(json['calculated_route']),
costs: (json['costs'] as List).map((e) => (e as num).toDouble()).toList(),
distance: (json['distance'] as num).toDouble(),
);
}
}
class Station {
final int id;
final String name;
final String network;
final String country;
Station({
required this.id,
required this.name,
required this.network,
required this.country,
});
factory Station.fromJson(Map<String, dynamic> json) => Station(
id: json['id'],
name: json['name'],
network: json['network'],
country: json['country'],
);
}