add android bundle release
All checks were successful
Release / meta (push) Successful in 10s
Release / linux-build (push) Successful in 6m32s
Release / web-build (push) Successful in 5m50s
Release / android-build (push) Successful in 20m43s
Release / release-master (push) Successful in 26s
Release / release-dev (push) Successful in 28s
All checks were successful
Release / meta (push) Successful in 10s
Release / linux-build (push) Successful in 6m32s
Release / web-build (push) Successful in 5m50s
Release / android-build (push) Successful in 20m43s
Release / release-master (push) Successful in 26s
Release / release-dev (push) Successful in 28s
This commit is contained in:
@@ -155,6 +155,18 @@ jobs:
|
|||||||
- name: Build Android App Bundle (release)
|
- name: Build Android App Bundle (release)
|
||||||
run: flutter build appbundle --release
|
run: flutter build appbundle --release
|
||||||
|
|
||||||
|
- name: Archive Android App Bundle
|
||||||
|
env:
|
||||||
|
BASE_VERSION: ${{ needs.meta.outputs.base_version }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
BUNDLE_SRC="build/app/outputs/bundle/release/app-release.aab"
|
||||||
|
if [ ! -f "$BUNDLE_SRC" ]; then
|
||||||
|
echo "Bundle not found at $BUNDLE_SRC"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
cp "$BUNDLE_SRC" "mileograph-${BASE_VERSION}.aab"
|
||||||
|
|
||||||
- name: Download bundletool
|
- name: Download bundletool
|
||||||
run: |
|
run: |
|
||||||
BUNDLETOOL_VERSION=1.15.6
|
BUNDLETOOL_VERSION=1.15.6
|
||||||
@@ -201,6 +213,12 @@ jobs:
|
|||||||
name: android-apk
|
name: android-apk
|
||||||
path: mileograph-${{ needs.meta.outputs.base_version }}.apk
|
path: mileograph-${{ needs.meta.outputs.base_version }}.apk
|
||||||
|
|
||||||
|
- name: Upload Android AAB artifact
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: android-aab
|
||||||
|
path: mileograph-${{ needs.meta.outputs.base_version }}.aab
|
||||||
|
|
||||||
linux-build:
|
linux-build:
|
||||||
runs-on:
|
runs-on:
|
||||||
- mileograph
|
- mileograph
|
||||||
@@ -383,6 +401,13 @@ jobs:
|
|||||||
name: android-apk
|
name: android-apk
|
||||||
path: artifacts
|
path: artifacts
|
||||||
|
|
||||||
|
- name: Download Android AAB
|
||||||
|
if: ${{ github.ref == 'refs/heads/dev' }}
|
||||||
|
uses: actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
name: android-aab
|
||||||
|
path: artifacts
|
||||||
|
|
||||||
- name: Prepare APK and tag
|
- name: Prepare APK and tag
|
||||||
if: ${{ github.ref == 'refs/heads/dev' }}
|
if: ${{ github.ref == 'refs/heads/dev' }}
|
||||||
id: bundle
|
id: bundle
|
||||||
@@ -397,11 +422,14 @@ jobs:
|
|||||||
|
|
||||||
VERSION="${BASE}${DEV_SUFFIX}"
|
VERSION="${BASE}${DEV_SUFFIX}"
|
||||||
APK_NAME="mileograph-${VERSION}.apk"
|
APK_NAME="mileograph-${VERSION}.apk"
|
||||||
|
AAB_NAME="mileograph-${VERSION}.aab"
|
||||||
|
|
||||||
mv "artifacts/mileograph-${BASE}.apk" "artifacts/${APK_NAME}"
|
mv "artifacts/mileograph-${BASE}.apk" "artifacts/${APK_NAME}"
|
||||||
|
mv "artifacts/mileograph-${BASE}.aab" "artifacts/${AAB_NAME}"
|
||||||
|
|
||||||
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
|
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
|
||||||
echo "apk=artifacts/${APK_NAME}" >> "$GITHUB_OUTPUT"
|
echo "apk=artifacts/${APK_NAME}" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "aab=artifacts/${AAB_NAME}" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
- name: Create prerelease on Gitea
|
- name: Create prerelease on Gitea
|
||||||
if: ${{ github.ref == 'refs/heads/dev' }}
|
if: ${{ github.ref == 'refs/heads/dev' }}
|
||||||
@@ -442,6 +470,18 @@ jobs:
|
|||||||
"${GITEA_BASE_URL}/api/v1/repos/${{ github.repository }}/releases/${RELEASE_ID}/assets" \
|
"${GITEA_BASE_URL}/api/v1/repos/${{ github.repository }}/releases/${RELEASE_ID}/assets" \
|
||||||
>/dev/null
|
>/dev/null
|
||||||
|
|
||||||
|
# Attach AAB
|
||||||
|
AAB="${{ steps.bundle.outputs.aab }}"
|
||||||
|
NAME_AAB=$(basename "$AAB")
|
||||||
|
echo "Uploading $NAME_AAB"
|
||||||
|
|
||||||
|
curl -sS -X POST \
|
||||||
|
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
|
||||||
|
-F "attachment=@${AAB}" \
|
||||||
|
-F "name=${NAME_AAB}" \
|
||||||
|
"${GITEA_BASE_URL}/api/v1/repos/${{ github.repository }}/releases/${RELEASE_ID}/assets" \
|
||||||
|
>/dev/null
|
||||||
|
|
||||||
release-master:
|
release-master:
|
||||||
runs-on:
|
runs-on:
|
||||||
- mileograph
|
- mileograph
|
||||||
@@ -467,6 +507,13 @@ jobs:
|
|||||||
name: android-apk
|
name: android-apk
|
||||||
path: artifacts
|
path: artifacts
|
||||||
|
|
||||||
|
- name: Download Android AAB
|
||||||
|
if: ${{ github.ref == 'refs/heads/master' }}
|
||||||
|
uses: actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
name: android-aab
|
||||||
|
path: artifacts
|
||||||
|
|
||||||
- name: Prepare APK and tag
|
- name: Prepare APK and tag
|
||||||
if: ${{ github.ref == 'refs/heads/master' }}
|
if: ${{ github.ref == 'refs/heads/master' }}
|
||||||
id: bundle
|
id: bundle
|
||||||
@@ -476,6 +523,7 @@ jobs:
|
|||||||
|
|
||||||
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
|
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
|
||||||
echo "apk=artifacts/mileograph-${BASE}.apk" >> "$GITHUB_OUTPUT"
|
echo "apk=artifacts/mileograph-${BASE}.apk" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "aab=artifacts/mileograph-${BASE}.aab" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
- name: Create release on Gitea
|
- name: Create release on Gitea
|
||||||
if: ${{ github.ref == 'refs/heads/master' }}
|
if: ${{ github.ref == 'refs/heads/master' }}
|
||||||
@@ -514,3 +562,15 @@ jobs:
|
|||||||
-F "name=${NAME}" \
|
-F "name=${NAME}" \
|
||||||
"${GITEA_BASE_URL}/api/v1/repos/${{ github.repository }}/releases/${RELEASE_ID}/assets" \
|
"${GITEA_BASE_URL}/api/v1/repos/${{ github.repository }}/releases/${RELEASE_ID}/assets" \
|
||||||
>/dev/null
|
>/dev/null
|
||||||
|
|
||||||
|
# Attach AAB
|
||||||
|
AAB="${{ steps.bundle.outputs.aab }}"
|
||||||
|
NAME_AAB=$(basename "$AAB")
|
||||||
|
echo "Uploading $NAME_AAB"
|
||||||
|
|
||||||
|
curl -sS -X POST \
|
||||||
|
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
|
||||||
|
-F "attachment=@${AAB}" \
|
||||||
|
-F "name=${NAME_AAB}" \
|
||||||
|
"${GITEA_BASE_URL}/api/v1/repos/${{ github.repository }}/releases/${RELEASE_ID}/assets" \
|
||||||
|
>/dev/null
|
||||||
|
|||||||
71
README.md
71
README.md
@@ -1,16 +1,67 @@
|
|||||||
# mileograph_flutter
|
# Mileograph (Flutter)
|
||||||
|
|
||||||
A new Flutter project.
|
Mileograph is a Flutter client for logging and analysing railway journeys. It lets you record legs, group them into trips, track locomotive mileage, and view stats and leaderboards.
|
||||||
|
|
||||||
## Getting Started
|
## Features
|
||||||
|
- Add and edit journey legs with traction, timings, routes, notes, and delays.
|
||||||
|
- Group legs into trips and see mileage totals and traction stats.
|
||||||
|
- Browse traction, view loco details, mileage leaderboards, timelines, and legs.
|
||||||
|
- Dashboard with homepage stats, “On This Day”, recent traction changes, and trips.
|
||||||
|
- Profile badges, class clearance progress, and traction progress.
|
||||||
|
- Offline-friendly UI built with Provider, GoRouter, and Material 3 styling.
|
||||||
|
|
||||||
This project is a starting point for a Flutter application.
|
## Project layout
|
||||||
|
- `lib/objects/objects.dart` — shared model classes and helpers.
|
||||||
|
- `lib/services/` — API, data loading, auth, endpoints, distance units.
|
||||||
|
- `lib/components/` — UI pages and widgets (entries, traction, dashboard, trips, settings, etc.).
|
||||||
|
- `assets/` — icons/fonts and other bundled assets.
|
||||||
|
|
||||||
A few resources to get you started if this is your first Flutter project:
|
## Prerequisites
|
||||||
|
- Flutter SDK (3.x or later recommended).
|
||||||
|
- Dart SDK (bundled with Flutter).
|
||||||
|
- A Mileograph API endpoint (set in Settings within the app).
|
||||||
|
|
||||||
- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
|
## Setup
|
||||||
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)
|
1) Install Flutter: follow https://docs.flutter.dev/get-started/install and ensure `flutter doctor` is green.
|
||||||
|
2) Get dependencies:
|
||||||
|
```bash
|
||||||
|
flutter pub get
|
||||||
|
```
|
||||||
|
3) Configure an API endpoint:
|
||||||
|
- Run the app, open Settings, and set the base URL for your Mileograph backend.
|
||||||
|
- The app probes the endpoint for a version string before saving.
|
||||||
|
|
||||||
For help getting started with Flutter development, view the
|
## Running
|
||||||
[online documentation](https://docs.flutter.dev/), which offers tutorials,
|
- Debug (mobile/web depending on your toolchain):
|
||||||
samples, guidance on mobile development, and a full API reference.
|
```bash
|
||||||
|
flutter run
|
||||||
|
```
|
||||||
|
- Release build (example for Android):
|
||||||
|
```bash
|
||||||
|
flutter build apk --release
|
||||||
|
```
|
||||||
|
|
||||||
|
## Testing and linting
|
||||||
|
- Static analysis: `flutter analyze`
|
||||||
|
- Unit/widget tests (if present): `flutter test`
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
1) Fork or branch from `main`.
|
||||||
|
2) Make changes with clear, small commits.
|
||||||
|
3) Add tests where feasible and keep `flutter analyze` clean.
|
||||||
|
4) Submit a PR describing:
|
||||||
|
- What changed and why.
|
||||||
|
- How to test or reproduce.
|
||||||
|
- Any API or migration notes.
|
||||||
|
|
||||||
|
### Coding conventions
|
||||||
|
- Prefer stateless widgets where possible; keep state localized.
|
||||||
|
- Use existing services in `lib/services` for API access; add new endpoints there.
|
||||||
|
- Keep models in `objects.dart` (or nearby files) and use helper parsers for defensive JSON handling.
|
||||||
|
- Follow Material theming already in use; keep strings user-facing and concise.
|
||||||
|
|
||||||
|
### Issue reporting
|
||||||
|
Include device/OS, Flutter version (`flutter --version`), steps to reproduce, expected vs. actual behaviour, and logs if available.
|
||||||
|
|
||||||
|
## License
|
||||||
|
Copyright © Mileograph contributors. See repository terms if provided.
|
||||||
|
|||||||
@@ -513,9 +513,9 @@ class _DashboardState extends State<Dashboard> {
|
|||||||
Widget _buildTripsCard(
|
Widget _buildTripsCard(
|
||||||
BuildContext context, DataService data, DistanceUnitService distanceUnits) {
|
BuildContext context, DataService data, DistanceUnitService distanceUnits) {
|
||||||
final tripsUnsorted = data.trips;
|
final tripsUnsorted = data.trips;
|
||||||
List trips = [];
|
List<TripSummary> trips = [];
|
||||||
if (tripsUnsorted.isNotEmpty) {
|
if (tripsUnsorted.isNotEmpty) {
|
||||||
trips = [...tripsUnsorted]..sort((a, b) => b.tripId.compareTo(a.tripId));
|
trips = [...tripsUnsorted]..sort(TripSummary.compareByDateDesc);
|
||||||
}
|
}
|
||||||
return _panel(
|
return _panel(
|
||||||
context,
|
context,
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ class MorePage extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _MoreHome extends StatelessWidget {
|
class _MoreHome extends StatelessWidget {
|
||||||
|
const _MoreHome({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ListView(
|
return ListView(
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ class _NewEntryPageState extends State<NewEntryPage> {
|
|||||||
|
|
||||||
Widget _buildTripSelector(BuildContext context) {
|
Widget _buildTripSelector(BuildContext context) {
|
||||||
final trips = context.watch<DataService>().tripList;
|
final trips = context.watch<DataService>().tripList;
|
||||||
final sorted = [...trips]..sort((a, b) => b.tripId.compareTo(a.tripId));
|
final sorted = [...trips]..sort(TripSummary.compareByDateDesc);
|
||||||
final tripIds = sorted.map((t) => t.tripId).toSet();
|
final tripIds = sorted.map((t) => t.tripId).toSet();
|
||||||
final selectedValue =
|
final selectedValue =
|
||||||
(_selectedTripId != null && tripIds.contains(_selectedTripId))
|
(_selectedTripId != null && tripIds.contains(_selectedTripId))
|
||||||
|
|||||||
@@ -232,7 +232,7 @@ class _TripsPageState extends State<TripsPage> {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
'Trip',
|
'Trip #${trip.id}',
|
||||||
style: Theme.of(context).textTheme.labelMedium,
|
style: Theme.of(context).textTheme.labelMedium,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 4),
|
const SizedBox(height: 4),
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:mileograph_flutter/objects/objects.dart';
|
import 'package:mileograph_flutter/objects/objects.dart';
|
||||||
|
import 'package:mileograph_flutter/services/api_service.dart';
|
||||||
import 'package:mileograph_flutter/services/distance_unit_service.dart';
|
import 'package:mileograph_flutter/services/distance_unit_service.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
@@ -210,6 +212,11 @@ Future<void> showTractionDetails(
|
|||||||
) async {
|
) async {
|
||||||
final hasMileageOrTrips = _hasMileageOrTrips(loco);
|
final hasMileageOrTrips = _hasMileageOrTrips(loco);
|
||||||
final distanceUnits = context.read<DistanceUnitService>();
|
final distanceUnits = context.read<DistanceUnitService>();
|
||||||
|
final api = context.read<ApiService>();
|
||||||
|
final leaderboardId = _leaderboardId(loco);
|
||||||
|
final leaderboardFuture = leaderboardId == null
|
||||||
|
? Future.value(const <LeaderboardEntry>[])
|
||||||
|
: _fetchLocoLeaderboard(api, leaderboardId);
|
||||||
await showModalBottomSheet(
|
await showModalBottomSheet(
|
||||||
context: context,
|
context: context,
|
||||||
isScrollControlled: true,
|
isScrollControlled: true,
|
||||||
@@ -295,6 +302,63 @@ Future<void> showTractionDetails(
|
|||||||
_detailRow(context, 'EVN', loco.evn ?? ''),
|
_detailRow(context, 'EVN', loco.evn ?? ''),
|
||||||
if (loco.notes != null && loco.notes!.isNotEmpty)
|
if (loco.notes != null && loco.notes!.isNotEmpty)
|
||||||
_detailRow(context, 'Notes', loco.notes!),
|
_detailRow(context, 'Notes', loco.notes!),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
Text(
|
||||||
|
'Leaderboard',
|
||||||
|
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||||
|
fontWeight: FontWeight.w700,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
FutureBuilder<List<LeaderboardEntry>>(
|
||||||
|
future: leaderboardFuture,
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||||
|
return const Padding(
|
||||||
|
padding: EdgeInsets.symmetric(vertical: 12.0),
|
||||||
|
child: Center(
|
||||||
|
child: SizedBox(
|
||||||
|
height: 24,
|
||||||
|
width: 24,
|
||||||
|
child: CircularProgressIndicator(strokeWidth: 2),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (snapshot.hasError) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||||
|
child: Text(
|
||||||
|
'Failed to load leaderboard',
|
||||||
|
style: Theme.of(context).textTheme.labelMedium?.copyWith(
|
||||||
|
color: Theme.of(context).colorScheme.error,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
final entries = snapshot.data ?? const <LeaderboardEntry>[];
|
||||||
|
if (entries.isEmpty) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||||
|
child: Text(
|
||||||
|
'No mileage leaderboard yet.',
|
||||||
|
style: Theme.of(context).textTheme.bodyMedium,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return Column(
|
||||||
|
children: entries.asMap().entries.map((entry) {
|
||||||
|
final rank = entry.key + 1;
|
||||||
|
return _leaderboardRow(
|
||||||
|
context,
|
||||||
|
rank,
|
||||||
|
entry.value,
|
||||||
|
distanceUnits,
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -307,6 +371,105 @@ Future<void> showTractionDetails(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<List<LeaderboardEntry>> _fetchLocoLeaderboard(
|
||||||
|
ApiService api,
|
||||||
|
int locoId,
|
||||||
|
) async {
|
||||||
|
try {
|
||||||
|
final json = await api.get('/loco/leaderboard/id/$locoId');
|
||||||
|
Iterable<dynamic>? raw;
|
||||||
|
if (json is List) {
|
||||||
|
raw = json;
|
||||||
|
} else if (json is Map) {
|
||||||
|
for (final key in ['data', 'leaderboard', 'results']) {
|
||||||
|
final value = json[key];
|
||||||
|
if (value is List) {
|
||||||
|
raw = value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (raw == null) return const [];
|
||||||
|
return raw.whereType<Map>().map((e) {
|
||||||
|
return LeaderboardEntry.fromJson(
|
||||||
|
e.map((key, value) => MapEntry(key.toString(), value)),
|
||||||
|
);
|
||||||
|
}).toList();
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('Failed to fetch loco leaderboard for $locoId: $e');
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int? _leaderboardId(LocoSummary loco) {
|
||||||
|
int? parse(dynamic value) {
|
||||||
|
if (value == null) return null;
|
||||||
|
if (value is int) return value == 0 ? null : value;
|
||||||
|
if (value is num) return value.toInt() == 0 ? null : value.toInt();
|
||||||
|
return int.tryParse(value.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return parse(loco.extra['loco_id']) ??
|
||||||
|
parse(loco.extra['id']) ??
|
||||||
|
parse(loco.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _leaderboardRow(
|
||||||
|
BuildContext context,
|
||||||
|
int rank,
|
||||||
|
LeaderboardEntry entry,
|
||||||
|
DistanceUnitService distanceUnits,
|
||||||
|
) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
final primaryName =
|
||||||
|
entry.userFullName.isNotEmpty ? entry.userFullName : entry.username;
|
||||||
|
final mileageLabel = distanceUnits.format(entry.mileage, decimals: 1);
|
||||||
|
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 6.0),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
width: 36,
|
||||||
|
height: 36,
|
||||||
|
alignment: Alignment.center,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: theme.colorScheme.primaryContainer,
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
'#$rank',
|
||||||
|
style: theme.textTheme.labelMedium?.copyWith(
|
||||||
|
fontWeight: FontWeight.w700,
|
||||||
|
color: theme.colorScheme.onPrimaryContainer,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 10),
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
primaryName,
|
||||||
|
style: theme.textTheme.bodyMedium?.copyWith(
|
||||||
|
fontWeight: FontWeight.w700,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
mileageLabel,
|
||||||
|
style: theme.textTheme.bodyMedium?.copyWith(
|
||||||
|
fontWeight: FontWeight.w700,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Widget _detailRow(BuildContext context, String label, String value) {
|
Widget _detailRow(BuildContext context, String label, String value) {
|
||||||
if (value.isEmpty) return const SizedBox.shrink();
|
if (value.isEmpty) return const SizedBox.shrink();
|
||||||
return Padding(
|
return Padding(
|
||||||
|
|||||||
@@ -66,6 +66,29 @@ DateTime _asDateTime(dynamic value, [DateTime? fallback]) {
|
|||||||
return parsed ?? (fallback ?? DateTime.fromMillisecondsSinceEpoch(0));
|
return parsed ?? (fallback ?? DateTime.fromMillisecondsSinceEpoch(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DateTime? _asNullableDateTime(dynamic value) {
|
||||||
|
if (value == null) return null;
|
||||||
|
if (value is DateTime) return value;
|
||||||
|
return DateTime.tryParse(value.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
int compareTripsByDateDesc(
|
||||||
|
DateTime? aDate,
|
||||||
|
DateTime? bDate,
|
||||||
|
int aId,
|
||||||
|
int bId,
|
||||||
|
) {
|
||||||
|
if (aDate != null && bDate != null) {
|
||||||
|
final cmp = bDate.compareTo(aDate);
|
||||||
|
if (cmp != 0) return cmp;
|
||||||
|
} else if (aDate != null) {
|
||||||
|
return -1;
|
||||||
|
} else if (bDate != null) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return bId.compareTo(aId);
|
||||||
|
}
|
||||||
|
|
||||||
class DestinationObject {
|
class DestinationObject {
|
||||||
const DestinationObject(
|
const DestinationObject(
|
||||||
this.label,
|
this.label,
|
||||||
@@ -443,7 +466,7 @@ class LocoSummary extends Loco {
|
|||||||
);
|
);
|
||||||
|
|
||||||
factory LocoSummary.fromJson(Map<String, dynamic> json) => LocoSummary(
|
factory LocoSummary.fromJson(Map<String, dynamic> json) => LocoSummary(
|
||||||
locoId: json['loco_id'] ?? json['id'] ?? 0,
|
locoId: _asInt(json['loco_id'] ?? json['id']),
|
||||||
locoType: json['type'] ?? json['loco_type'] ?? '',
|
locoType: json['type'] ?? json['loco_type'] ?? '',
|
||||||
locoNumber: json['number'] ?? json['loco_number'] ?? '',
|
locoNumber: json['number'] ?? json['loco_number'] ?? '',
|
||||||
locoName: json['name'] ?? json['loco_name'] ?? "",
|
locoName: json['name'] ?? json['loco_name'] ?? "",
|
||||||
@@ -722,9 +745,12 @@ class TripSummary {
|
|||||||
final double tripMileage;
|
final double tripMileage;
|
||||||
final int legCount;
|
final int legCount;
|
||||||
final List<TripLocoStat> locoStats;
|
final List<TripLocoStat> locoStats;
|
||||||
|
final DateTime? startDate;
|
||||||
|
final DateTime? endDate;
|
||||||
|
|
||||||
int get locoHadCount => locoStats.length;
|
int get locoHadCount => locoStats.length;
|
||||||
int get winnersCount => locoStats.where((e) => e.won).length;
|
int get winnersCount => locoStats.where((e) => e.won).length;
|
||||||
|
DateTime? get primaryDate => endDate ?? startDate;
|
||||||
|
|
||||||
TripSummary({
|
TripSummary({
|
||||||
required this.tripId,
|
required this.tripId,
|
||||||
@@ -732,20 +758,72 @@ class TripSummary {
|
|||||||
required this.tripMileage,
|
required this.tripMileage,
|
||||||
this.legCount = 0,
|
this.legCount = 0,
|
||||||
List<TripLocoStat>? locoStats,
|
List<TripLocoStat>? locoStats,
|
||||||
|
this.startDate,
|
||||||
|
this.endDate,
|
||||||
}) : locoStats = locoStats ?? const [];
|
}) : locoStats = locoStats ?? const [];
|
||||||
|
|
||||||
factory TripSummary.fromJson(Map<String, dynamic> json) => TripSummary(
|
static int compareByDateDesc(TripSummary a, TripSummary b) =>
|
||||||
tripId: _asInt(json['trip_id']),
|
compareTripsByDateDesc(a.primaryDate, b.primaryDate, a.tripId, b.tripId);
|
||||||
tripName: _asString(json['trip_name']),
|
|
||||||
tripMileage: _asDouble(json['trip_mileage']),
|
factory TripSummary.fromJson(Map<String, dynamic> json) {
|
||||||
legCount: _asInt(
|
DateTime? startDate;
|
||||||
json['leg_count'],
|
DateTime? endDate;
|
||||||
(json['trip_legs'] as List?)?.length ?? 0,
|
|
||||||
),
|
DateTime? parseDate(dynamic value) => _asNullableDateTime(value);
|
||||||
locoStats: TripLocoStat.listFromJson(
|
|
||||||
json['stats'] ?? json['trip_locos'] ?? json['locos'],
|
for (final key in [
|
||||||
),
|
'trip_begin_time',
|
||||||
);
|
'trip_start',
|
||||||
|
'trip_start_time',
|
||||||
|
'trip_date',
|
||||||
|
'start_date',
|
||||||
|
'date',
|
||||||
|
]) {
|
||||||
|
startDate ??= parseDate(json[key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (final key in [
|
||||||
|
'trip_end_time',
|
||||||
|
'trip_finish_time',
|
||||||
|
'trip_end',
|
||||||
|
'end_date',
|
||||||
|
]) {
|
||||||
|
endDate ??= parseDate(json[key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (json['trip_legs'] is List) {
|
||||||
|
for (final leg in json['trip_legs'] as List) {
|
||||||
|
DateTime? begin;
|
||||||
|
if (leg is TripLeg) {
|
||||||
|
begin = leg.beginTime;
|
||||||
|
} else if (leg is Map) {
|
||||||
|
begin = parseDate(leg['leg_begin_time']);
|
||||||
|
}
|
||||||
|
if (begin == null) continue;
|
||||||
|
if (startDate == null || begin.isBefore(startDate)) {
|
||||||
|
startDate = begin;
|
||||||
|
}
|
||||||
|
if (endDate == null || begin.isAfter(endDate)) {
|
||||||
|
endDate = begin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return TripSummary(
|
||||||
|
tripId: _asInt(json['trip_id']),
|
||||||
|
tripName: _asString(json['trip_name']),
|
||||||
|
tripMileage: _asDouble(json['trip_mileage']),
|
||||||
|
legCount: _asInt(
|
||||||
|
json['leg_count'],
|
||||||
|
(json['trip_legs'] as List?)?.length ?? 0,
|
||||||
|
),
|
||||||
|
locoStats: TripLocoStat.listFromJson(
|
||||||
|
json['stats'] ?? json['trip_locos'] ?? json['locos'],
|
||||||
|
),
|
||||||
|
startDate: startDate,
|
||||||
|
endDate: endDate,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Leg {
|
class Leg {
|
||||||
@@ -941,6 +1019,34 @@ class TripDetail {
|
|||||||
|
|
||||||
int get locoHadCount => locoStats.length;
|
int get locoHadCount => locoStats.length;
|
||||||
int get winnersCount => locoStats.where((e) => e.won).length;
|
int get winnersCount => locoStats.where((e) => e.won).length;
|
||||||
|
DateTime? get startDate {
|
||||||
|
DateTime? earliest;
|
||||||
|
for (final leg in legs) {
|
||||||
|
final begin = leg.beginTime;
|
||||||
|
if (begin == null) continue;
|
||||||
|
if (earliest == null || begin.isBefore(earliest)) {
|
||||||
|
earliest = begin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return earliest;
|
||||||
|
}
|
||||||
|
|
||||||
|
DateTime? get endDate {
|
||||||
|
DateTime? latest;
|
||||||
|
for (final leg in legs) {
|
||||||
|
final begin = leg.beginTime;
|
||||||
|
if (begin == null) continue;
|
||||||
|
if (latest == null || begin.isAfter(latest)) {
|
||||||
|
latest = begin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return latest;
|
||||||
|
}
|
||||||
|
|
||||||
|
DateTime? get primaryDate => endDate ?? startDate;
|
||||||
|
|
||||||
|
static int compareByDateDesc(TripDetail a, TripDetail b) =>
|
||||||
|
compareTripsByDateDesc(a.primaryDate, b.primaryDate, a.id, b.id);
|
||||||
|
|
||||||
TripDetail({
|
TripDetail({
|
||||||
required this.id,
|
required this.id,
|
||||||
|
|||||||
@@ -151,7 +151,8 @@ class DataService extends ChangeNotifier {
|
|||||||
try {
|
try {
|
||||||
final json = await api.get('/stats/homepage');
|
final json = await api.get('/stats/homepage');
|
||||||
_homepageStats = HomepageStats.fromJson(json);
|
_homepageStats = HomepageStats.fromJson(json);
|
||||||
_trips = _homepageStats?.trips ?? [];
|
_trips = [...(_homepageStats?.trips ?? const [])]
|
||||||
|
..sort(TripSummary.compareByDateDesc);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugPrint('Failed to fetch homepage stats: $e');
|
debugPrint('Failed to fetch homepage stats: $e');
|
||||||
_homepageStats = null;
|
_homepageStats = null;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ extension DataServiceTrips on DataService {
|
|||||||
try {
|
try {
|
||||||
final json = await api.get('/trips/info');
|
final json = await api.get('/trips/info');
|
||||||
final tripDetails = _parseTripInfoList(json);
|
final tripDetails = _parseTripInfoList(json);
|
||||||
_tripDetails = [...tripDetails]..sort((a, b) => b.id.compareTo(a.id));
|
_tripDetails = [...tripDetails]..sort(TripDetail.compareByDateDesc);
|
||||||
_tripList = tripDetails
|
_tripList = tripDetails
|
||||||
.map(
|
.map(
|
||||||
(detail) => TripSummary(
|
(detail) => TripSummary(
|
||||||
@@ -15,10 +15,12 @@ extension DataServiceTrips on DataService {
|
|||||||
tripMileage: detail.mileage,
|
tripMileage: detail.mileage,
|
||||||
legCount: detail.legCount,
|
legCount: detail.legCount,
|
||||||
locoStats: detail.locoStats,
|
locoStats: detail.locoStats,
|
||||||
|
startDate: detail.startDate,
|
||||||
|
endDate: detail.endDate,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.toList()
|
.toList()
|
||||||
..sort((a, b) => b.tripId.compareTo(a.tripId));
|
..sort(TripSummary.compareByDateDesc);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugPrint('Failed to fetch trip_map: $e');
|
debugPrint('Failed to fetch trip_map: $e');
|
||||||
_tripDetails = [];
|
_tripDetails = [];
|
||||||
@@ -49,7 +51,7 @@ extension DataServiceTrips on DataService {
|
|||||||
.map((e) => TripSummary.fromJson(e))
|
.map((e) => TripSummary.fromJson(e))
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
_tripList = [...tripMap]..sort((a, b) => b.tripId.compareTo(a.tripId));
|
_tripList = [...tripMap]..sort(TripSummary.compareByDateDesc);
|
||||||
} else {
|
} else {
|
||||||
debugPrint('Unexpected trip list response: $json');
|
debugPrint('Unexpected trip list response: $json');
|
||||||
_tripList = [];
|
_tripList = [];
|
||||||
@@ -83,7 +85,7 @@ extension DataServiceTrips on DataService {
|
|||||||
.map((e) => TripSummary.fromJson(e))
|
.map((e) => TripSummary.fromJson(e))
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
_tripList = [...tripMap]..sort((a, b) => b.tripId.compareTo(a.tripId));
|
_tripList = [...tripMap]..sort(TripSummary.compareByDateDesc);
|
||||||
} else {
|
} else {
|
||||||
debugPrint('Unexpected trip list response: $json');
|
debugPrint('Unexpected trip list response: $json');
|
||||||
_tripList = [];
|
_tripList = [];
|
||||||
@@ -105,7 +107,7 @@ extension DataServiceTrips on DataService {
|
|||||||
} else {
|
} else {
|
||||||
_tripList = [trip, ..._tripList];
|
_tripList = [trip, ..._tripList];
|
||||||
}
|
}
|
||||||
_tripList.sort((a, b) => b.tripId.compareTo(a.tripId));
|
_tripList.sort(TripSummary.compareByDateDesc);
|
||||||
_notifyAsync();
|
_notifyAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
|
|||||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||||
# In Windows, build-name is used as the major, minor, and patch parts
|
# In Windows, build-name is used as the major, minor, and patch parts
|
||||||
# of the product and file versions while build-number is used as the build suffix.
|
# of the product and file versions while build-number is used as the build suffix.
|
||||||
version: 0.5.3+1
|
version: 0.5.4+1
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.8.1
|
sdk: ^3.8.1
|
||||||
|
|||||||
Reference in New Issue
Block a user