123 lines
3.2 KiB
Dart
123 lines
3.2 KiB
Dart
import 'package:flutter/material.dart';
|
||
import 'dart:async';
|
||
import 'movie.dart';
|
||
import 'genre.dart';
|
||
import 'movieGenerator.dart';
|
||
|
||
|
||
void main() {
|
||
runApp(const MyApp());
|
||
}
|
||
|
||
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 'Психологический триллер';
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
class MyApp extends StatelessWidget {
|
||
const MyApp({super.key});
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return MaterialApp(
|
||
title: 'Flutter Demo',
|
||
theme: ThemeData(
|
||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.pink),
|
||
useMaterial3: true,
|
||
),
|
||
home: const MyHomePage(title: 'Булатовa Каринa Раилевна'),
|
||
);
|
||
}
|
||
}
|
||
|
||
class MyHomePage extends StatefulWidget {
|
||
const MyHomePage({super.key, required this.title});
|
||
|
||
final String title;
|
||
|
||
@override
|
||
State<MyHomePage> createState() => _MyHomePageState();
|
||
}
|
||
|
||
class _MyHomePageState extends State<MyHomePage> {
|
||
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);
|
||
|
||
setState(() {
|
||
_movies = sortedMovies;
|
||
_isLoading = false;
|
||
});
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Scaffold(
|
||
appBar: AppBar(
|
||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||
title: Text(widget.title),
|
||
),
|
||
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('Жанр: ${movie.genre.description}, Рейтинг: ${movie.rating.toStringAsFixed(1)}'),
|
||
onTap: () {
|
||
movie.printDetails();
|
||
showDialog(
|
||
context: context,
|
||
builder: (context) {
|
||
return AlertDialog(
|
||
|
||
title: Text(movie.title),
|
||
content: Column(
|
||
mainAxisSize: MainAxisSize.min,
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Text('Жанр: ${movie.genre.description}'),
|
||
Text('Рейтинг: ${movie.rating.toStringAsFixed(1)}'),
|
||
],
|
||
),
|
||
actions: [
|
||
TextButton(
|
||
onPressed: () {
|
||
Navigator.of(context).pop();
|
||
},
|
||
child: const Text('Закрыть'),
|
||
),
|
||
],
|
||
);
|
||
},
|
||
);
|
||
},
|
||
);
|
||
},
|
||
),
|
||
);
|
||
}
|
||
} |