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:
@@ -1,5 +1,7 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.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:provider/provider.dart';
|
||||
|
||||
@@ -210,6 +212,11 @@ Future<void> showTractionDetails(
|
||||
) async {
|
||||
final hasMileageOrTrips = _hasMileageOrTrips(loco);
|
||||
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(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
@@ -295,6 +302,63 @@ Future<void> showTractionDetails(
|
||||
_detailRow(context, 'EVN', loco.evn ?? ''),
|
||||
if (loco.notes != null && loco.notes!.isNotEmpty)
|
||||
_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) {
|
||||
if (value.isEmpty) return const SizedBox.shrink();
|
||||
return Padding(
|
||||
|
||||
Reference in New Issue
Block a user