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
|
|
|
|
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),
|
2024-10-02 13:15:15 +04:00
|
|
|
|
subtitle: Text('Жанр: ${movie.genre.description}, Рейтинг: ${movie.rating.toStringAsFixed(1)}'),
|
2024-09-22 21:49:20 +04:00
|
|
|
|
onTap: () {
|
2024-10-02 13:15:15 +04:00
|
|
|
|
movie.printDetails();
|
2024-09-22 21:49:20 +04:00
|
|
|
|
showDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (context) {
|
|
|
|
|
return AlertDialog(
|
2024-10-02 13:15:15 +04:00
|
|
|
|
|
2024-09-22 21:49:20 +04:00
|
|
|
|
title: Text(movie.title),
|
|
|
|
|
content: Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
2024-10-02 13:15:15 +04:00
|
|
|
|
Text('Жанр: ${movie.genre.description}'),
|
|
|
|
|
Text('Рейтинг: ${movie.rating.toStringAsFixed(1)}'),
|
2024-09-22 21:49:20 +04:00
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
actions: [
|
|
|
|
|
TextButton(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
},
|
2024-10-02 13:15:15 +04:00
|
|
|
|
child: const Text('Закрыть'),
|
2024-09-22 21:49:20 +04:00
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
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
|
|
|
|
}
|