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';
|
|
|
|
|
|
|
|
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
|
|
|
|
Widget build(Object context) {
|
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++;
|
|
|
|
}
|
|
|
|
return ListView.builder(
|
|
|
|
itemCount: indexMap.length,
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
return MovieItem(movies[indexMap[index]]);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2023-11-06 10:38:26 +01:00
|
|
|
return ListView.builder(
|
|
|
|
itemCount: movies.length,
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
return MovieItem(movies[index]);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|