release_schedule/lib/view/movie_list.dart

37 lines
966 B
Dart
Raw Normal View History

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});
@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]]);
},
);
}
return ListView.builder(
itemCount: movies.length,
itemBuilder: (context, index) {
return MovieItem(movies[index]);
},
);
}
}