Five Good

This commit is contained in:
Serxiolog 2024-11-18 15:06:34 +04:00
parent 96016dcfe3
commit bfd46aca31
6 changed files with 58 additions and 33 deletions

View File

@ -5,6 +5,7 @@ extension AnimeDataDtoToModel on AnimeDataDto {
CardData toDomain() => CardData(
title ?? 'NOT',
imageUrl: images?.jpg?.image ?? "NONE",
description: synopsis ?? "NONE",
score ?? 8,
description: synopsis == null ? "NONE" : synopsis!.split('\n').sublist(0, synopsis!.split('\n').length - 1).join('\n'),
);
}

View File

@ -8,10 +8,12 @@ class MockRepository extends ApiInterface {
return [
const CardData(
"First",
5,
description: "SomeText",
),
const CardData(
"Second",
8,
icon: Icons.gamepad,
description: "ManyText",
imageUrl:
@ -19,6 +21,7 @@ class MockRepository extends ApiInterface {
),
const CardData(
"Third",
9,
icon: Icons.offline_bolt_outlined,
description: "Wow >_<",
),

View File

@ -10,13 +10,14 @@ class DetailsPage extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Column(
body: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(bottom: 16),
child: Image.network(
data.imageUrl ?? '',
data.imageUrl,
),
),
Padding(
@ -31,6 +32,7 @@ class DetailsPage extends StatelessWidget {
)
],
),
),
);
}
}

View File

@ -1,5 +1,3 @@
import 'dart:math';
import 'package:first_project/presentation/home_page/home_page.dart';
import 'package:flutter/material.dart';
@ -22,3 +20,4 @@ class MyApp extends StatelessWidget {
);
}
}

View File

@ -6,10 +6,12 @@ class CardData {
final String text;
final String description;
final IconData icon;
final double score;
final String imageUrl;
const CardData(
this.text, {
this.text,
this.score, {
required this.description,
this.icon = Icons.add_call,
this.imageUrl =
@ -21,6 +23,7 @@ class _Card extends StatefulWidget {
final String text;
final String description;
final String? imageUrl;
final double score;
final OnLikeCallback onLike;
final VoidCallback? onTap;
@ -28,6 +31,7 @@ class _Card extends StatefulWidget {
this.text, {
required this.description,
required this.imageUrl,
required this.score,
this.onLike,
this.onTap,
});
@ -41,6 +45,7 @@ class _Card extends StatefulWidget {
data.text,
description: data.description,
imageUrl: data.imageUrl,
score: data.score,
onLike: onLike,
onTap: onTap,
);
@ -54,6 +59,8 @@ class _CardState extends State<_Card> {
@override
Widget build(BuildContext context) {
List<String> desc = widget.description.split("\n");
return GestureDetector(
onTap: widget.onTap,
child: Container(
@ -82,7 +89,7 @@ class _CardState extends State<_Card> {
topLeft: Radius.circular(18),
),
child: SizedBox(
height: double.infinity,
height: 300,
width: 120,
child: Image.network(
widget.imageUrl ?? '',
@ -100,7 +107,7 @@ class _CardState extends State<_Card> {
topRight: Radius.circular(20),
bottomLeft: Radius.circular(18))),
padding: const EdgeInsets.fromLTRB(8, 2, 8, 2),
child: Text('Новинка',
child: Text(generateStars(widget.score),
style: Theme.of(context)
.textTheme
.bodyMedium
@ -117,10 +124,10 @@ class _CardState extends State<_Card> {
children: [
Text(
widget.text,
style: Theme.of(context).textTheme.headlineLarge,
style: Theme.of(context).textTheme.headlineMedium,
),
Text(
widget.description,
desc[0],
style: Theme.of(context).textTheme.bodySmall,
)
],
@ -162,3 +169,16 @@ class _CardState extends State<_Card> {
);
}
}
String generateStars(double rating) {
rating = rating / 2;
int fullStars = rating.floor();
bool hasHalfStar = (rating - fullStars) >= 0.5;
String stars = '' * fullStars;
if (hasHalfStar) {
stars += '';
}
int emptyStars = 5 - stars.length;
stars += '' * emptyStars;
return stars;
}

View File

@ -138,10 +138,10 @@ packages:
dependency: transitive
description:
name: code_builder
sha256: f692079e25e7869c14132d39f223f8eec9830eb76131925143b2129c4bb01b37
sha256: "0ec10bf4a89e4c613960bf1e8b42c64127021740fb21640c29c909826a5eea3e"
url: "https://pub.dev"
source: hosted
version: "4.10.0"
version: "4.10.1"
collection:
dependency: transitive
description:
@ -348,10 +348,10 @@ packages:
dependency: transitive
description:
name: logging
sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340"
sha256: c8245ada5f1717ed44271ed1c26b8ce85ca3228fd2ffdb75468ab01979309d61
url: "https://pub.dev"
source: hosted
version: "1.2.0"
version: "1.3.0"
macros:
dependency: transitive
description:
@ -545,10 +545,10 @@ packages:
dependency: transitive
description:
name: typed_data
sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c
sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006
url: "https://pub.dev"
source: hosted
version: "1.3.2"
version: "1.4.0"
vector_math:
dependency: transitive
description: