Coursework is Done
This commit is contained in:
parent
a4fcdc5715
commit
3bcd01be43
@ -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) {
|
||||
|
@ -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<HomeData?> 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',
|
||||
),
|
||||
),
|
||||
];
|
||||
|
@ -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,
|
9
lib/domain/models/character.dart
Normal file
9
lib/domain/models/character.dart
Normal file
@ -0,0 +1,9 @@
|
||||
class CharacterData {
|
||||
final String name;
|
||||
final String? avatarUrl;
|
||||
|
||||
CharacterData({
|
||||
required this.name,
|
||||
this.avatarUrl,
|
||||
});
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
import 'package:pmu_labworks/domain/models/comment.dart';
|
||||
import 'package:pmu_labworks/domain/models/card.dart';
|
||||
|
||||
class HomeData {
|
||||
final List<CommentData>? data;
|
||||
final List<CardData>? data;
|
||||
final int? nextPage;
|
||||
|
||||
HomeData({this.data, this.nextPage});
|
||||
|
@ -1,9 +0,0 @@
|
||||
class UserData {
|
||||
final String nickname;
|
||||
final String? avatarUrl;
|
||||
|
||||
UserData({
|
||||
required this.nickname,
|
||||
this.avatarUrl,
|
||||
});
|
||||
}
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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)),
|
||||
|
Loading…
Reference in New Issue
Block a user