diff --git a/lib/data/mappers/anime_mapper.dart b/lib/data/mappers/anime_mapper.dart index 04cdd1f..287d309 100644 --- a/lib/data/mappers/anime_mapper.dart +++ b/lib/data/mappers/anime_mapper.dart @@ -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'), ); } \ No newline at end of file diff --git a/lib/data/repositories/mock_repository.dart b/lib/data/repositories/mock_repository.dart index 4105276..fb942ff 100644 --- a/lib/data/repositories/mock_repository.dart +++ b/lib/data/repositories/mock_repository.dart @@ -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 >_<", ), diff --git a/lib/domain/models/card.dart b/lib/domain/models/card.dart index b8b92cb..e64da91 100644 --- a/lib/domain/models/card.dart +++ b/lib/domain/models/card.dart @@ -10,26 +10,28 @@ class DetailsPage extends StatelessWidget { Widget build(BuildContext context) { return Scaffold( appBar: AppBar(), - body: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - padding: const EdgeInsets.only(bottom: 16), - child: Image.network( - data.imageUrl ?? '', + body: SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: const EdgeInsets.only(bottom: 16), + child: Image.network( + data.imageUrl, + ), ), - ), - Padding( - padding: const EdgeInsets.only(bottom: 4), - child: Text( - data.text, - style: Theme.of(context).textTheme.headlineLarge, - )), - Text( - data.description, - style: Theme.of(context).textTheme.bodyLarge, - ) - ], + Padding( + padding: const EdgeInsets.only(bottom: 4), + child: Text( + data.text, + style: Theme.of(context).textTheme.headlineLarge, + )), + Text( + data.description, + style: Theme.of(context).textTheme.bodyLarge, + ) + ], + ), ), ); } diff --git a/lib/main.dart b/lib/main.dart index 90b1b4b..f805e9d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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 { ); } } + diff --git a/lib/presentation/home_page/card.dart b/lib/presentation/home_page/card.dart index c237563..bb75c67 100644 --- a/lib/presentation/home_page/card.dart +++ b/lib/presentation/home_page/card.dart @@ -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 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; +} diff --git a/pubspec.lock b/pubspec.lock index 55bbb91..afc0e0f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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: