101 lines
3.5 KiB
Dart
101 lines
3.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:mileograph_flutter/services/data_service.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
class LeaderboardPanel extends StatelessWidget {
|
|
const LeaderboardPanel({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final data = context.watch<DataService>();
|
|
final leaderboard = data.homepageStats?.leaderboard ?? [];
|
|
final textTheme = Theme.of(context).textTheme;
|
|
if (data.isHomepageLoading && leaderboard.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.emoji_events, size: 20),
|
|
const SizedBox(width: 8),
|
|
Expanded(
|
|
child: Text(
|
|
"Leaderboard",
|
|
style: textTheme.titleMedium?.copyWith(
|
|
fontWeight: FontWeight.w800,
|
|
),
|
|
),
|
|
),
|
|
if (leaderboard.isNotEmpty)
|
|
Container(
|
|
padding:
|
|
const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
|
decoration: BoxDecoration(
|
|
color: Theme.of(context).colorScheme.surfaceContainerHighest,
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
child: Text(
|
|
'Top ${leaderboard.length}',
|
|
style: textTheme.labelSmall,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 8),
|
|
if (leaderboard.isEmpty)
|
|
const Padding(
|
|
padding: EdgeInsets.all(8.0),
|
|
child: Text('No leaderboard data yet'),
|
|
)
|
|
else
|
|
Column(
|
|
children: [
|
|
for (int index = 0; index < leaderboard.length; index++) ...[
|
|
ListTile(
|
|
contentPadding: EdgeInsets.zero,
|
|
dense: true,
|
|
leading: CircleAvatar(
|
|
radius: 18,
|
|
backgroundColor:
|
|
Theme.of(context).colorScheme.secondaryContainer,
|
|
child: Text(
|
|
'${index + 1}',
|
|
style: textTheme.labelLarge?.copyWith(
|
|
fontWeight: FontWeight.w800,
|
|
),
|
|
),
|
|
),
|
|
title: Text(
|
|
leaderboard[index].userFullName,
|
|
style: textTheme.titleSmall?.copyWith(
|
|
fontWeight: FontWeight.w700,
|
|
),
|
|
),
|
|
trailing: Text(
|
|
'${leaderboard[index].mileage.toStringAsFixed(1)} mi',
|
|
style: textTheme.labelLarge?.copyWith(
|
|
fontWeight: FontWeight.w700,
|
|
),
|
|
),
|
|
),
|
|
if (index != leaderboard.length - 1) const Divider(height: 12),
|
|
],
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|