92 lines
3.1 KiB
Dart
92 lines
3.1 KiB
Dart
// lib/widgets/activity/activity_sport_groups_view.dart
|
|
import 'package:aves/model/activity/activity_preview_point.dart';
|
|
import 'package:aves/model/activity/activity_grouping.dart';
|
|
import 'package:aves/widgets/activity/preview/activity_entry_preview.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class ActivitySportGroupsView extends StatelessWidget {
|
|
final List<ActivitySportGroup> groups;
|
|
final Map<int, List<ActivityPreviewPoint>> previewPointsByActivityId;
|
|
final Future<void> Function() onRefresh;
|
|
final ValueChanged<ActivitySportGroup> onTap;
|
|
|
|
const ActivitySportGroupsView({
|
|
super.key,
|
|
required this.groups,
|
|
required this.previewPointsByActivityId,
|
|
required this.onRefresh,
|
|
required this.onTap,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (groups.isEmpty) {
|
|
return Center(
|
|
child: TextButton.icon(
|
|
onPressed: onRefresh,
|
|
icon: const Icon(Icons.refresh),
|
|
label: const Text('Nessuno sport trovato. Ricarica'),
|
|
),
|
|
);
|
|
}
|
|
|
|
return RefreshIndicator(
|
|
onRefresh: onRefresh,
|
|
child: GridView.builder(
|
|
padding: const EdgeInsets.fromLTRB(12, 12, 12, 96),
|
|
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
|
crossAxisCount: 2,
|
|
mainAxisSpacing: 12,
|
|
crossAxisSpacing: 12,
|
|
childAspectRatio: 1.05,
|
|
),
|
|
itemCount: groups.length,
|
|
itemBuilder: (context, index) {
|
|
final group = groups[index];
|
|
final cover = group.coverEntry;
|
|
|
|
final points = cover?.id == null ? const <ActivityPreviewPoint>[] : previewPointsByActivityId[cover!.id!] ?? const <ActivityPreviewPoint>[];
|
|
|
|
return Card(
|
|
clipBehavior: Clip.antiAlias,
|
|
child: InkWell(
|
|
onTap: () => onTap(group),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Expanded(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(12),
|
|
child: ActivityEntryPreview(
|
|
points: points,
|
|
size: 120,
|
|
),
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(12, 0, 12, 4),
|
|
child: Text(
|
|
group.displayName,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(12, 0, 12, 12),
|
|
child: Text(
|
|
'${group.count} attività',
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|