2023-11-06 10:38:26 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:release_schedule/model/movie.dart';
|
|
|
|
import 'package:release_schedule/view/movie_item.dart';
|
2024-01-09 14:48:36 +01:00
|
|
|
import 'package:sticky_grouped_list/sticky_grouped_list.dart';
|
2023-11-06 10:38:26 +01:00
|
|
|
|
|
|
|
class MovieList extends StatelessWidget {
|
|
|
|
final List<MovieData> movies;
|
2024-01-08 12:57:36 +01:00
|
|
|
final bool Function(MovieData)? filter;
|
|
|
|
const MovieList(this.movies, {this.filter, super.key});
|
2023-11-06 10:38:26 +01:00
|
|
|
|
|
|
|
@override
|
2024-01-09 14:48:36 +01:00
|
|
|
Widget build(BuildContext context) {
|
|
|
|
Widget buildGroupSeparator(BuildContext context, DateWithPrecision date) {
|
|
|
|
bool highlight = date.includes(DateTime.now());
|
|
|
|
return SizedBox(
|
|
|
|
height: 50,
|
|
|
|
child: Align(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Card(
|
|
|
|
elevation: 5,
|
|
|
|
color: highlight
|
|
|
|
? Theme.of(context).colorScheme.primaryContainer
|
|
|
|
: null,
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
horizontal: 12,
|
|
|
|
vertical: 8,
|
|
|
|
),
|
|
|
|
child: Text(
|
|
|
|
date.toString(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-01-08 12:57:36 +01:00
|
|
|
final localFilter = filter;
|
|
|
|
if (localFilter != null) {
|
|
|
|
List<int> indexMap = [];
|
|
|
|
int index = 0;
|
|
|
|
for (var movie in movies) {
|
|
|
|
if (localFilter(movie)) {
|
|
|
|
indexMap.add(index);
|
|
|
|
}
|
|
|
|
index++;
|
|
|
|
}
|
2024-01-09 14:48:36 +01:00
|
|
|
return StickyGroupedListView<int, DateWithPrecision>(
|
|
|
|
elements: indexMap,
|
|
|
|
floatingHeader: true,
|
|
|
|
groupBy: (index) => movies[index].releaseDate.dateWithPrecision,
|
|
|
|
groupSeparatorBuilder: (index) => buildGroupSeparator(
|
|
|
|
context, movies[index].releaseDate.dateWithPrecision),
|
2024-01-08 12:57:36 +01:00
|
|
|
itemBuilder: (context, index) {
|
2024-01-09 14:48:36 +01:00
|
|
|
return MovieItem(movies[index]);
|
2024-01-08 12:57:36 +01:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2024-01-09 14:48:36 +01:00
|
|
|
return StickyGroupedListView<MovieData, DateWithPrecision>(
|
|
|
|
elements: movies,
|
|
|
|
floatingHeader: true,
|
|
|
|
groupBy: (movie) => movie.releaseDate.dateWithPrecision,
|
|
|
|
groupSeparatorBuilder: (movie) =>
|
|
|
|
buildGroupSeparator(context, movie.releaseDate.dateWithPrecision),
|
|
|
|
itemBuilder: (context, movie) {
|
|
|
|
return MovieItem(movie);
|
2023-11-06 10:38:26 +01:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|