PIbd-32_Bulatova_K._R._PMU/lib/movieGenerator.dart

25 lines
678 B
Dart
Raw Normal View History

2024-09-22 21:49:20 +04:00
import 'movie.dart';
import 'genre.dart';
import 'dart:math';
class MovieGenerator {
final int count;
MovieGenerator({required this.count});
Future<List<Movie>> generateMoviesWithDelay() async {
await Future.delayed(Duration(seconds: 2));
final random = Random();
return List.generate(count, (index) {
final title = 'Movie ${index + 1}';
final genre = Genre.values[random.nextInt(Genre.values.length)];
final rating = random.nextDouble() * 10;
return Movie(title: title, genre: genre, rating: rating);
});
}
List<Movie> sortMovies(List<Movie> movies) {
return movies..sort((a, b) => b.rating.compareTo(a.rating));
}
}