2024-09-18 17:00:02 +04:00
|
|
|
|
import 'package:flutter/material.dart';
|
2024-09-22 21:49:20 +04:00
|
|
|
|
import 'dart:async';
|
|
|
|
|
import 'movie.dart';
|
|
|
|
|
import 'genre.dart';
|
|
|
|
|
import 'movieGenerator.dart';
|
|
|
|
|
|
2024-09-18 17:00:02 +04:00
|
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
|
runApp(const MyApp());
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-22 21:49:20 +04:00
|
|
|
|
// Расширение для Genre, добавляющее метод для получения описания жанра
|
|
|
|
|
extension GenreExtension on Genre {
|
|
|
|
|
String get description {
|
|
|
|
|
switch (this) {
|
|
|
|
|
case Genre.action:
|
|
|
|
|
return 'Боевик!!!';
|
|
|
|
|
case Genre.comedy:
|
|
|
|
|
return 'Прикольная комедия';
|
|
|
|
|
case Genre.drama:
|
|
|
|
|
return 'Грустная драма';
|
|
|
|
|
case Genre.thriller:
|
|
|
|
|
return 'Психологический триллер';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-09-18 17:00:02 +04:00
|
|
|
|
class MyApp extends StatelessWidget {
|
|
|
|
|
const MyApp({super.key});
|
|
|
|
|
|
2024-09-22 21:49:20 +04:00
|
|
|
|
@override
|
2024-09-18 17:00:02 +04:00
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return MaterialApp(
|
|
|
|
|
title: 'Flutter Demo',
|
|
|
|
|
theme: ThemeData(
|
|
|
|
|
colorScheme: ColorScheme.fromSeed(seedColor: Colors.pink),
|
|
|
|
|
useMaterial3: true,
|
|
|
|
|
),
|
2024-09-22 19:55:08 +04:00
|
|
|
|
home: const MyHomePage(title: 'Булатовa Каринa Раилевна'),
|
2024-09-18 17:00:02 +04:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class MyHomePage extends StatefulWidget {
|
|
|
|
|
const MyHomePage({super.key, required this.title});
|
|
|
|
|
|
|
|
|
|
final String title;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<MyHomePage> createState() => _MyHomePageState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _MyHomePageState extends State<MyHomePage> {
|
2024-09-22 21:49:20 +04:00
|
|
|
|
List<Movie> _movies = [];
|
|
|
|
|
bool _isLoading = true;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
_loadMovies();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _loadMovies() async {
|
|
|
|
|
final generator = MovieGenerator(count: 5);
|
|
|
|
|
final movies = await generator.generateMoviesWithDelay();
|
|
|
|
|
final sortedMovies = generator.sortMovies(movies);
|
2024-09-18 17:00:02 +04:00
|
|
|
|
|
|
|
|
|
setState(() {
|
2024-09-22 21:49:20 +04:00
|
|
|
|
_movies = sortedMovies;
|
|
|
|
|
_isLoading = false;
|
2024-09-18 17:00:02 +04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2024-09-22 21:49:20 +04:00
|
|
|
|
return Scaffold(
|
2024-09-18 17:00:02 +04:00
|
|
|
|
appBar: AppBar(
|
2024-09-22 21:49:20 +04:00
|
|
|
|
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
|
|
|
|
title: Text(widget.title),
|
2024-09-18 17:00:02 +04:00
|
|
|
|
),
|
2024-09-22 21:49:20 +04:00
|
|
|
|
body: _isLoading
|
|
|
|
|
? const Center(child: CircularProgressIndicator())
|
|
|
|
|
: ListView.builder(
|
|
|
|
|
itemCount: _movies.length,
|
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
|
final movie = _movies[index];
|
|
|
|
|
return ListTile(
|
|
|
|
|
title: Text(movie.title),
|
|
|
|
|
subtitle: Text('Genre: ${movie.genre.description}, Rating: ${movie.rating.toStringAsFixed(1)}'),
|
|
|
|
|
onTap: () {
|
|
|
|
|
showDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (context) {
|
|
|
|
|
return AlertDialog(
|
|
|
|
|
title: Text(movie.title),
|
|
|
|
|
content: Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Text('Genre: ${movie.genre.description}'),
|
|
|
|
|
Text('Rating: ${movie.rating.toStringAsFixed(1)}'),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
actions: [
|
|
|
|
|
TextButton(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
},
|
|
|
|
|
child: const Text('Close'),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
2024-09-18 17:00:02 +04:00
|
|
|
|
),
|
2024-09-22 21:49:20 +04:00
|
|
|
|
);
|
2024-09-18 17:00:02 +04:00
|
|
|
|
}
|
2024-09-22 21:49:20 +04:00
|
|
|
|
}
|