25 lines
678 B
Dart
25 lines
678 B
Dart
|
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));
|
||
|
}
|
||
|
}
|