Coursework is Done

This commit is contained in:
parent a4fcdc5715
commit 3bcd01be43
9 changed files with 48 additions and 49 deletions

View File

@ -1,7 +1,7 @@
import 'package:pmu_labworks/data/dtos/characters_dto.dart'; 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/home.dart';
import 'package:pmu_labworks/domain/models/user.dart'; import 'package:pmu_labworks/domain/models/character.dart';
extension CharactersDtoToModel on CharactersDto { extension CharactersDtoToModel on CharactersDto {
HomeData toDomain() => HomeData( HomeData toDomain() => HomeData(
@ -11,11 +11,11 @@ extension CharactersDtoToModel on CharactersDto {
} }
extension CharacterDataDtoToModel on CharacterDataDto { extension CharacterDataDtoToModel on CharacterDataDto {
CommentData toDomain() => CommentData( CardData toDomain() => CardData(
id: id, id: id,
title: type ?? 'UNKNOWN', title: type ?? 'UNKNOWN',
text: _makeDescriptionText(attributes?.born, attributes?.died), 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) { String _makeDescriptionText(String? born, String? died) {

View File

@ -1,49 +1,49 @@
import 'package:pmu_labworks/data/repositories/api_interface.dart'; 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/home.dart';
import 'package:pmu_labworks/domain/models/user.dart'; import 'package:pmu_labworks/domain/models/character.dart';
class MockRepository extends ApiInterface { class MockRepository extends ApiInterface {
@override @override
Future<HomeData?> loadData({OnErrorCallback? onError}) async { Future<HomeData?> loadData({OnErrorCallback? onError}) async {
final data = [ final data = [
CommentData( CardData(
title: 'Oh my god', title: 'Oh my god',
text: 'this app is so cool ' * 10, text: 'this app is so cool ' * 10,
user: UserData( user: CharacterData(
nickname: 'Steve', name: 'Steve',
avatarUrl: 'https://preview.free3d.com/img/2016/03/1875481443430303321/hld8c0oa.jpg', avatarUrl: 'https://preview.free3d.com/img/2016/03/1875481443430303321/hld8c0oa.jpg',
), ),
), ),
CommentData( CardData(
title: 'Listen to me', title: 'Listen to me',
text: 'This app is like Half-Life 3 - it will never be released', text: 'This app is like Half-Life 3 - it will never be released',
user: UserData( user: CharacterData(
nickname: 'G-Man', name: 'G-Man',
avatarUrl: avatarUrl:
'https://us-tuna-sounds-images.voicemod.net/356aeabd-18d5-40d8-af31-b479f4eff183-1704672174928.png', 'https://us-tuna-sounds-images.voicemod.net/356aeabd-18d5-40d8-af31-b479f4eff183-1704672174928.png',
), ),
), ),
CommentData( CardData(
title: 'BREAKING!!!', title: 'BREAKING!!!',
text: 'ONLY NOW you can purchase the ability to put likes and dislikes for only 299\$', text: 'ONLY NOW you can purchase the ability to put likes and dislikes for only 299\$',
user: UserData( user: CharacterData(
nickname: 'Bethesda', name: 'Bethesda',
avatarUrl: 'https://i.playground.ru/p/BWixorSTeZQfoPvdVL9lgA.jpeg', avatarUrl: 'https://i.playground.ru/p/BWixorSTeZQfoPvdVL9lgA.jpeg',
), ),
), ),
CommentData( CardData(
title: 'Test', title: 'Test',
text: 'Test', text: 'Test',
user: UserData( user: CharacterData(
nickname: 'Noname', name: 'Noname',
), ),
), ),
CommentData( CardData(
title: 'Test', title: 'Test',
text: 'Test', text: 'Test',
user: UserData( user: CharacterData(
nickname: 'Noname', name: 'Noname',
), ),
), ),
]; ];

View File

@ -1,12 +1,12 @@
import 'user.dart'; import 'character.dart';
class CommentData { class CardData {
final String? id; final String? id;
final String title; final String title;
final String text; final String text;
final UserData user; final CharacterData user;
CommentData({ CardData({
this.id, this.id,
required this.title, required this.title,
required this.text, required this.text,

View File

@ -0,0 +1,9 @@
class CharacterData {
final String name;
final String? avatarUrl;
CharacterData({
required this.name,
this.avatarUrl,
});
}

View File

@ -1,7 +1,7 @@
import 'package:pmu_labworks/domain/models/comment.dart'; import 'package:pmu_labworks/domain/models/card.dart';
class HomeData { class HomeData {
final List<CommentData>? data; final List<CardData>? data;
final int? nextPage; final int? nextPage;
HomeData({this.data, this.nextPage}); HomeData({this.data, this.nextPage});

View File

@ -1,9 +0,0 @@
class UserData {
final String nickname;
final String? avatarUrl;
UserData({
required this.nickname,
this.avatarUrl,
});
}

View File

@ -1,9 +1,9 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:pmu_labworks/components/extensions/context_x.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 { class DetailsPage extends StatelessWidget {
final CommentData model; final CardData model;
const DetailsPage(this.model, {super.key}); const DetailsPage(this.model, {super.key});
@ -12,7 +12,7 @@ class DetailsPage extends StatelessWidget {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text( title: Text(
context.locale.comment(model.user.nickname), context.locale.comment(model.user.name),
), ),
), ),
body: Padding( body: Padding(
@ -45,7 +45,7 @@ class DetailsPage extends StatelessWidget {
padding: const EdgeInsets.symmetric(vertical: 4.0, horizontal: 8.0), padding: const EdgeInsets.symmetric(vertical: 4.0, horizontal: 8.0),
color: Colors.black.withOpacity(0.6), color: Colors.black.withOpacity(0.6),
child: Text( child: Text(
_shortenNickname(model.user.nickname, maxLength: 13), _shortenNickname(model.user.name, maxLength: 13),
style: const TextStyle( style: const TextStyle(
color: Colors.white, color: Colors.white,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,

View File

@ -7,7 +7,7 @@ class _Comment extends StatelessWidget {
final String? id; final String? id;
final String title; final String title;
final String text; final String text;
final UserData user; final CharacterData user;
final bool isLiked; final bool isLiked;
final bool isDisliked; final bool isDisliked;
final OnReactionCallback? onLike; final OnReactionCallback? onLike;
@ -27,7 +27,7 @@ class _Comment extends StatelessWidget {
}); });
factory _Comment.fromData( factory _Comment.fromData(
CommentData data, { CardData data, {
bool isLiked = false, bool isLiked = false,
bool isDisliked = false, bool isDisliked = false,
OnReactionCallback? onLike, OnReactionCallback? onLike,
@ -47,11 +47,11 @@ class _Comment extends StatelessWidget {
); );
void _onLike() { void _onLike() {
onLike?.call(id, user.nickname, isLiked, isDisliked); onLike?.call(id, user.name, isLiked, isDisliked);
} }
void _onDislike() { void _onDislike() {
onDislike?.call(id, user.nickname, isLiked, isDisliked); onDislike?.call(id, user.name, isLiked, isDisliked);
} }
@override @override
@ -101,7 +101,7 @@ class _Comment extends StatelessWidget {
SizedBox( SizedBox(
width: 80, width: 80,
child: Text( child: Text(
user.nickname, user.name,
style: Theme.of(context).textTheme.bodyMedium, style: Theme.of(context).textTheme.bodyMedium,
maxLines: 1, maxLines: 1,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,

View File

@ -1,4 +1,3 @@
import 'dart:io';
import 'dart:math'; import 'dart:math';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
@ -6,8 +5,8 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:pmu_labworks/components/extensions/context_x.dart'; import 'package:pmu_labworks/components/extensions/context_x.dart';
import 'package:pmu_labworks/components/utils/debounce.dart'; import 'package:pmu_labworks/components/utils/debounce.dart';
import 'package:pmu_labworks/domain/models/comment.dart'; import 'package:pmu_labworks/domain/models/card.dart';
import 'package:pmu_labworks/domain/models/user.dart'; import 'package:pmu_labworks/domain/models/character.dart';
import 'package:pmu_labworks/view/common/svg_objects.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/details_page/details_page.dart';
import 'package:pmu_labworks/view/home_page/bloc/bloc.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( Navigator.push(
context, context,
CupertinoPageRoute(builder: (context) => DetailsPage(data)), CupertinoPageRoute(builder: (context) => DetailsPage(data)),