154 lines
3.9 KiB
Dart
154 lines
3.9 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 LocoSummary {
|
|
final String locoType, locoClass, locoNumber, locoName, locoOperator;
|
|
final String? locoNotes, locoEvn;
|
|
final int locoId, locoJourneys;
|
|
final double locoMileage;
|
|
|
|
LocoSummary({
|
|
required this.locoType,
|
|
required this.locoClass,
|
|
required this.locoNumber,
|
|
required this.locoName,
|
|
required this.locoOperator,
|
|
this.locoNotes,
|
|
this.locoEvn,
|
|
required this.locoId,
|
|
required this.locoMileage,
|
|
required this.locoJourneys,
|
|
});
|
|
|
|
factory LocoSummary.fromJson(Map<String, dynamic> json) => LocoSummary(
|
|
locoType: json['loco_type'],
|
|
locoClass: json['loco_class'],
|
|
locoNumber: json['loco_number'],
|
|
locoName: json['loco_name'],
|
|
locoOperator: json['loco_operator'],
|
|
locoNotes: json['loco_notes'],
|
|
locoEvn: json['loco_evn'],
|
|
locoId: json['loco_id'],
|
|
locoMileage: (json['loco_mileage'] as num).toDouble(),
|
|
locoJourneys: json['loco_journeys'],
|
|
);
|
|
}
|
|
|
|
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(),
|
|
);
|
|
}
|