Files
mileograph_flutter/lib/components/dashboard/top_traction_panel.dart
Pete Gregory b1a8f7baf4
All checks were successful
Release / meta (push) Successful in 8s
Release / linux-build (push) Successful in 7m15s
Release / android-build (push) Successful in 18m37s
Release / release-master (push) Successful in 23s
Release / release-dev (push) Successful in 26s
dashboard overhaul
2025-12-22 19:39:50 +00:00

97 lines
3.3 KiB
Dart

import 'package:flutter/material.dart';
import 'package:mileograph_flutter/services/data_service.dart';
import 'package:provider/provider.dart';
class TopTractionPanel extends StatelessWidget {
const TopTractionPanel({super.key});
@override
Widget build(BuildContext context) {
final data = context.watch<DataService>();
final stats = data.homepageStats;
final locos = stats?.topLocos ?? [];
final textTheme = Theme.of(context).textTheme;
if (data.isHomepageLoading && locos.isEmpty) {
return const Padding(
padding: EdgeInsets.all(16.0),
child: Center(child: CircularProgressIndicator()),
);
}
return Card(
clipBehavior: Clip.antiAlias,
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
children: [
const Icon(Icons.train, size: 20),
const SizedBox(width: 8),
Expanded(
child: Text(
"Top traction",
style: textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w800,
),
),
),
],
),
const SizedBox(height: 8),
if (locos.isEmpty)
const Padding(
padding: EdgeInsets.all(8.0),
child: Text('No traction data yet'),
)
else
Column(
children: [
for (int index = 0; index < locos.length; index++) ...[
ListTile(
contentPadding: EdgeInsets.zero,
dense: true,
leading: CircleAvatar(
radius: 18,
backgroundColor:
Theme.of(context).colorScheme.primaryContainer,
child: Text(
'${index + 1}',
style: textTheme.labelLarge?.copyWith(
fontWeight: FontWeight.w800,
),
),
),
title: Text(
'${locos[index].locoClass} ${locos[index].number}',
style: textTheme.titleSmall?.copyWith(
fontWeight: FontWeight.w700,
),
),
subtitle: (locos[index].name ?? '').isEmpty
? null
: Text(
locos[index].name ?? '',
style: textTheme.bodySmall?.copyWith(
fontStyle: FontStyle.italic,
),
),
trailing: Text(
'${locos[index].mileage?.toStringAsFixed(1)} mi',
style: textTheme.labelLarge?.copyWith(
fontWeight: FontWeight.w700,
),
),
),
if (index != locos.length - 1) const Divider(height: 12),
],
],
),
],
),
),
);
}
}