diff --git a/lib/data/mappers/characters_mapper.dart b/lib/data/mappers/characters_mapper.dart index b3d8ef0..f778e3e 100644 --- a/lib/data/mappers/characters_mapper.dart +++ b/lib/data/mappers/characters_mapper.dart @@ -1,7 +1,7 @@ import 'package:pmu_labworks/data/dtos/characters_dto.dart'; -import 'package:pmu_labworks/domain/models/comment.dart'; +import 'package:pmu_labworks/domain/models/card.dart'; import 'package:pmu_labworks/domain/models/home.dart'; -import 'package:pmu_labworks/domain/models/user.dart'; +import 'package:pmu_labworks/domain/models/character.dart'; extension CharactersDtoToModel on CharactersDto { HomeData toDomain() => HomeData( @@ -11,11 +11,11 @@ extension CharactersDtoToModel on CharactersDto { } extension CharacterDataDtoToModel on CharacterDataDto { - CommentData toDomain() => CommentData( + CardData toDomain() => CardData( id: id, title: type ?? 'UNKNOWN', text: _makeDescriptionText(attributes?.born, attributes?.died), - user: UserData(nickname: attributes?.name ?? 'Noname', avatarUrl: attributes?.image), + user: CharacterData(name: attributes?.name ?? 'Noname', avatarUrl: attributes?.image), ); String _makeDescriptionText(String? born, String? died) { diff --git a/lib/data/repositories/mock_repository.dart b/lib/data/repositories/mock_repository.dart index da9a711..4412453 100644 --- a/lib/data/repositories/mock_repository.dart +++ b/lib/data/repositories/mock_repository.dart @@ -1,49 +1,49 @@ import 'package:pmu_labworks/data/repositories/api_interface.dart'; -import 'package:pmu_labworks/domain/models/comment.dart'; +import 'package:pmu_labworks/domain/models/card.dart'; import 'package:pmu_labworks/domain/models/home.dart'; -import 'package:pmu_labworks/domain/models/user.dart'; +import 'package:pmu_labworks/domain/models/character.dart'; class MockRepository extends ApiInterface { @override Future loadData({OnErrorCallback? onError}) async { final data = [ - CommentData( + CardData( title: 'Oh my god', text: 'this app is so cool ' * 10, - user: UserData( - nickname: 'Steve', + user: CharacterData( + name: 'Steve', avatarUrl: 'https://preview.free3d.com/img/2016/03/1875481443430303321/hld8c0oa.jpg', ), ), - CommentData( + CardData( title: 'Listen to me', text: 'This app is like Half-Life 3 - it will never be released', - user: UserData( - nickname: 'G-Man', + user: CharacterData( + name: 'G-Man', avatarUrl: 'https://us-tuna-sounds-images.voicemod.net/356aeabd-18d5-40d8-af31-b479f4eff183-1704672174928.png', ), ), - CommentData( + CardData( title: 'BREAKING!!!', text: 'ONLY NOW you can purchase the ability to put likes and dislikes for only 299\$', - user: UserData( - nickname: 'Bethesda', + user: CharacterData( + name: 'Bethesda', avatarUrl: 'https://i.playground.ru/p/BWixorSTeZQfoPvdVL9lgA.jpeg', ), ), - CommentData( + CardData( title: 'Test', text: 'Test', - user: UserData( - nickname: 'Noname', + user: CharacterData( + name: 'Noname', ), ), - CommentData( + CardData( title: 'Test', text: 'Test', - user: UserData( - nickname: 'Noname', + user: CharacterData( + name: 'Noname', ), ), ]; diff --git a/lib/domain/models/comment.dart b/lib/domain/models/card.dart similarity index 65% rename from lib/domain/models/comment.dart rename to lib/domain/models/card.dart index 02d79ac..205ad35 100644 --- a/lib/domain/models/comment.dart +++ b/lib/domain/models/card.dart @@ -1,12 +1,12 @@ -import 'user.dart'; +import 'character.dart'; -class CommentData { +class CardData { final String? id; final String title; final String text; - final UserData user; + final CharacterData user; - CommentData({ + CardData({ this.id, required this.title, required this.text, diff --git a/lib/domain/models/character.dart b/lib/domain/models/character.dart new file mode 100644 index 0000000..bcb97d9 --- /dev/null +++ b/lib/domain/models/character.dart @@ -0,0 +1,9 @@ +class CharacterData { + final String name; + final String? avatarUrl; + + CharacterData({ + required this.name, + this.avatarUrl, + }); +} diff --git a/lib/domain/models/home.dart b/lib/domain/models/home.dart index 9e5a7a7..a14f5e2 100644 --- a/lib/domain/models/home.dart +++ b/lib/domain/models/home.dart @@ -1,7 +1,7 @@ -import 'package:pmu_labworks/domain/models/comment.dart'; +import 'package:pmu_labworks/domain/models/card.dart'; class HomeData { - final List? data; + final List? data; final int? nextPage; HomeData({this.data, this.nextPage}); diff --git a/lib/domain/models/user.dart b/lib/domain/models/user.dart deleted file mode 100644 index a47f23e..0000000 --- a/lib/domain/models/user.dart +++ /dev/null @@ -1,9 +0,0 @@ -class UserData { - final String nickname; - final String? avatarUrl; - - UserData({ - required this.nickname, - this.avatarUrl, - }); -} diff --git a/lib/view/details_page/details_page.dart b/lib/view/details_page/details_page.dart index a36fc54..0a68720 100644 --- a/lib/view/details_page/details_page.dart +++ b/lib/view/details_page/details_page.dart @@ -1,9 +1,9 @@ import 'package:flutter/material.dart'; import 'package:pmu_labworks/components/extensions/context_x.dart'; -import 'package:pmu_labworks/domain/models/comment.dart'; +import 'package:pmu_labworks/domain/models/card.dart'; class DetailsPage extends StatelessWidget { - final CommentData model; + final CardData model; const DetailsPage(this.model, {super.key}); @@ -12,7 +12,7 @@ class DetailsPage extends StatelessWidget { return Scaffold( appBar: AppBar( title: Text( - context.locale.comment(model.user.nickname), + context.locale.comment(model.user.name), ), ), body: Padding( @@ -45,7 +45,7 @@ class DetailsPage extends StatelessWidget { padding: const EdgeInsets.symmetric(vertical: 4.0, horizontal: 8.0), color: Colors.black.withOpacity(0.6), child: Text( - _shortenNickname(model.user.nickname, maxLength: 13), + _shortenNickname(model.user.name, maxLength: 13), style: const TextStyle( color: Colors.white, fontWeight: FontWeight.bold, diff --git a/lib/view/home_page/comment.dart b/lib/view/home_page/comment.dart index ae41074..01a58d1 100644 --- a/lib/view/home_page/comment.dart +++ b/lib/view/home_page/comment.dart @@ -7,7 +7,7 @@ class _Comment extends StatelessWidget { final String? id; final String title; final String text; - final UserData user; + final CharacterData user; final bool isLiked; final bool isDisliked; final OnReactionCallback? onLike; @@ -27,7 +27,7 @@ class _Comment extends StatelessWidget { }); factory _Comment.fromData( - CommentData data, { + CardData data, { bool isLiked = false, bool isDisliked = false, OnReactionCallback? onLike, @@ -47,11 +47,11 @@ class _Comment extends StatelessWidget { ); void _onLike() { - onLike?.call(id, user.nickname, isLiked, isDisliked); + onLike?.call(id, user.name, isLiked, isDisliked); } void _onDislike() { - onDislike?.call(id, user.nickname, isLiked, isDisliked); + onDislike?.call(id, user.name, isLiked, isDisliked); } @override @@ -101,7 +101,7 @@ class _Comment extends StatelessWidget { SizedBox( width: 80, child: Text( - user.nickname, + user.name, style: Theme.of(context).textTheme.bodyMedium, maxLines: 1, overflow: TextOverflow.ellipsis, diff --git a/lib/view/home_page/home_page.dart b/lib/view/home_page/home_page.dart index 91f8082..961cad3 100644 --- a/lib/view/home_page/home_page.dart +++ b/lib/view/home_page/home_page.dart @@ -1,4 +1,3 @@ -import 'dart:io'; import 'dart:math'; import 'package:flutter/cupertino.dart'; @@ -6,8 +5,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:pmu_labworks/components/extensions/context_x.dart'; import 'package:pmu_labworks/components/utils/debounce.dart'; -import 'package:pmu_labworks/domain/models/comment.dart'; -import 'package:pmu_labworks/domain/models/user.dart'; +import 'package:pmu_labworks/domain/models/card.dart'; +import 'package:pmu_labworks/domain/models/character.dart'; import 'package:pmu_labworks/view/common/svg_objects.dart'; import 'package:pmu_labworks/view/details_page/details_page.dart'; import 'package:pmu_labworks/view/home_page/bloc/bloc.dart'; @@ -222,7 +221,7 @@ class _BodyState extends State<_Body> { } } - void _navToDetails(BuildContext context, CommentData data) { + void _navToDetails(BuildContext context, CardData data) { Navigator.push( context, CupertinoPageRoute(builder: (context) => DetailsPage(data)),