ну вроде сделала третью лабу

This commit is contained in:
bulatova_karina 2024-10-02 16:47:37 +04:00
parent bc6079d0da
commit 1089462d47
4 changed files with 155 additions and 123 deletions

View File

@ -1,6 +0,0 @@
enum Genre {
action,
comedy,
drama,
thriller,
}

View File

@ -1,30 +1,9 @@
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});
@ -36,7 +15,7 @@ class MyApp extends StatelessWidget {
colorScheme: ColorScheme.fromSeed(seedColor: Colors.pink),
useMaterial3: true,
),
home: const MyHomePage(title: 'Булатовa Каринa Раилевна'),
home: const MyHomePage(title: 'Булатова Каринa Раилевна'),
);
}
}
@ -51,23 +30,11 @@ class MyHomePage extends StatefulWidget {
}
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);
int _counter = 0;
void _incrementCounter() {
setState(() {
_movies = sortedMovies;
_isLoading = false;
_counter++;
});
}
@ -78,45 +45,157 @@ class _MyHomePageState extends State<MyHomePage> {
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(
body: const MyWidget(),
);
}
}
title: Text(movie.title),
content: Column(
mainAxisSize: MainAxisSize.min,
class _CardData {
final String text;
final String descriptionText;
final IconData icon;
final String? imageUrl;
_CardData(
this.text, {
required this.descriptionText,
this.icon = Icons.ac_unit_outlined,
this.imageUrl,
});
}
class MyWidget extends StatelessWidget {
const MyWidget({super.key});
@override
Widget build(BuildContext context) {
final data = [
_CardData(
'Человек-паук',
descriptionText: 'Чела укусил паук блин',
imageUrl:
'https://i.pinimg.com/564x/1b/be/e7/1bbee75b44e22793c42c48e01d3ce3fc.jpg',
),
_CardData(
'Drive',
descriptionText: 'Райан Гослинг в фильме драйв',
icon: Icons.star,
imageUrl:
'https://i.pinimg.com/564x/24/3f/7e/243f7e8772ed0ff547a403466c99b3ce.jpg',
),
_CardData(
'Головоломка',
descriptionText: 'Мультфильм про эмоции',
icon: Icons.woman,
imageUrl:
'https://i.pinimg.com/564x/3d/af/1e/3daf1ec0832cf3d6e0bff9db194564f5.jpg',
),
_CardData(
'Бойцовский клуб',
descriptionText: 'Это чтоо, Тайлер Дердер???',
icon: Icons.question_answer,
imageUrl:
'https://i.pinimg.com/564x/e6/a6/61/e6a661bd29efdeee24e56c930398acca.jpg',
),
_CardData(
'Рапунцель',
descriptionText: 'Очень мили мультик',
icon: Icons.favorite_border,
imageUrl:
'https://i.pinimg.com/564x/17/46/6b/17466b0834d4a62a23bf0995e78cfc71.jpg',
),
];
return Center(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: data.map((e) => _Card.fromData(e)).toList(),
),
));
}
}
class _Card extends StatelessWidget {
final String text;
final String descriptionText;
final IconData icon;
final String? imageUrl;
const _Card(
this.text, {
this.icon = Icons.ac_unit_outlined,
required this.descriptionText,
this.imageUrl,
});
factory _Card.fromData(_CardData data) => _Card(
data.text,
descriptionText: data.descriptionText,
icon: data.icon,
imageUrl: data.imageUrl,
);
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.only(top: 16),
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white70,
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: Colors.grey,
width: 2,
),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(.5),
spreadRadius: 4,
offset: const Offset(0, 5),
blurRadius: 8,
)
]
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Жанр: ${movie.genre.description}'),
Text('Рейтинг: ${movie.rating.toStringAsFixed(1)}'),
ClipRRect(
borderRadius: BorderRadius.circular(20),
child: SizedBox(
height: 140,
width: 100,
child: Image.network(
imageUrl ?? '',
fit: BoxFit.cover,
errorBuilder: (_, __, ___) => const Placeholder(),
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
text,
style: Theme.of(context).textTheme.headlineLarge,
),
Text(
descriptionText,
style: Theme.of(context).textTheme.bodyLarge,
)
],
),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('Закрыть'),
),
),
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Icon(icon),
),
],
);
},
);
},
);
},
),
);
}

View File

@ -1,16 +0,0 @@
import 'package:project1/main.dart';
import 'genre.dart';
class Movie {
final String title;
final Genre genre;
final double rating;
Movie({required this.title, required this.genre, required this.rating});
void printDetails() {
print('''Title: $title
Genre: ${genre.description}
Rating: $rating''');
}
}

View File

@ -1,25 +0,0 @@
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));
}
}