некоторые правки
This commit is contained in:
parent
e031ca847e
commit
937649c4fb
@ -2,6 +2,16 @@ import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'thrones_character_dto.g.dart';
|
||||
|
||||
@JsonSerializable(createToJson: false)
|
||||
class ThronesCharacterListDto {
|
||||
final List<ThronesCharacterDto> characters;
|
||||
|
||||
ThronesCharacterListDto({required this.characters});
|
||||
|
||||
factory ThronesCharacterListDto.fromJson(Map<String, dynamic> json) =>
|
||||
_$ThronesCharacterListDtoFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable(createToJson: false)
|
||||
class ThronesCharacterDto {
|
||||
final int id;
|
||||
|
@ -6,6 +6,14 @@ part of 'thrones_character_dto.dart';
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
ThronesCharacterListDto _$ThronesCharacterListDtoFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
ThronesCharacterListDto(
|
||||
characters: (json['characters'] as List<dynamic>)
|
||||
.map((e) => ThronesCharacterDto.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
);
|
||||
|
||||
ThronesCharacterDto _$ThronesCharacterDtoFromJson(Map<String, dynamic> json) =>
|
||||
ThronesCharacterDto(
|
||||
id: (json['id'] as num).toInt(),
|
||||
|
@ -7,14 +7,14 @@ const _imagePlaceholder =
|
||||
|
||||
extension ThronesCharacterDtoToModel on ThronesCharacterDto {
|
||||
CardData toDomain() => CardData(
|
||||
descriptionText: _makeDescriptionText(title, family),
|
||||
text: _makeDescriptionText(title, family),
|
||||
firstName: firstName,
|
||||
lastName: lastName,
|
||||
title: title,
|
||||
family: family,
|
||||
fullName: fullName,
|
||||
imageUrl: imageUrl,
|
||||
text: '',
|
||||
id: id.toString()
|
||||
);
|
||||
|
||||
String _makeDescriptionText(String? title, String? family) {
|
||||
|
@ -1,75 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_app/data/repositories/api_interface.dart';
|
||||
import 'package:flutter_app/domain/models/card.dart';
|
||||
|
||||
// class MockRepository extends ApiInterface {
|
||||
// @override
|
||||
// Future<List<CardData>?> loadData({OnErrorCallback? onError}) async {
|
||||
// return [
|
||||
// CardData(
|
||||
// fullName: 'Daenerys Targaryen',
|
||||
// descriptionText: 'Mother of Dragons',
|
||||
// icon: Icons.favorite,
|
||||
// imageUrl:
|
||||
// 'https://thronesapi.com/assets/images/daenerys.jpg',
|
||||
// text: '', firstName: '', lastName: '', title: '', family: '',
|
||||
// ),
|
||||
// CardData(
|
||||
// fullName: 'Samwell Tarly',
|
||||
// descriptionText: 'Maester',
|
||||
// icon: Icons.favorite,
|
||||
// imageUrl:
|
||||
// 'https://thronesapi.com/assets/images/sam.jpg',
|
||||
// text: '', firstName: '', lastName: '', title: '', family: '',
|
||||
// ),
|
||||
// CardData(
|
||||
// fullName: 'Jon Snow',
|
||||
// descriptionText: 'King of the North',
|
||||
// icon: Icons.favorite,
|
||||
// imageUrl:
|
||||
// 'https://thronesapi.com/assets/images/jon-snow.jpg',
|
||||
// text: '', firstName: '', lastName: '', title: '', family: '',
|
||||
// ),
|
||||
// CardData(
|
||||
// fullName: 'Arya Stark',
|
||||
// descriptionText: 'No One',
|
||||
// icon: Icons.favorite,
|
||||
// imageUrl:
|
||||
// 'https://thronesapi.com/assets/images/arya-stark.jpg',
|
||||
// text: '', firstName: '', lastName: '', title: '', family: '',
|
||||
// ),
|
||||
// CardData(
|
||||
// fullName: 'Sansa Stark',
|
||||
// descriptionText: 'Lady of Winterfell',
|
||||
// icon: Icons.favorite,
|
||||
// imageUrl:
|
||||
// 'https://thronesapi.com/assets/images/sansa-stark.jpeg',
|
||||
// text: '', firstName: '', lastName: '', title: '', family: '',
|
||||
// ),
|
||||
// CardData(
|
||||
// fullName: 'Brandon Stark',
|
||||
// descriptionText: 'Lord of Winterfell',
|
||||
// icon: Icons.favorite,
|
||||
// imageUrl:
|
||||
// 'https://thronesapi.com/assets/images/bran-stark.jpg',
|
||||
// text: '', firstName: '', lastName: '', title: '', family: '',
|
||||
// ),
|
||||
// CardData(
|
||||
// fullName: 'Ned Stark',
|
||||
// descriptionText: 'Lord of Winterfell',
|
||||
// icon: Icons.favorite,
|
||||
// imageUrl:
|
||||
// 'https://thronesapi.com/assets/images/ned-stark.jpg',
|
||||
// text: '', firstName: '', lastName: '', title: '', family: '',
|
||||
// ),
|
||||
// CardData(
|
||||
// fullName: 'Robert Baratheon',
|
||||
// descriptionText: 'Lord of the Seven Kingdoms',
|
||||
// icon: Icons.favorite,
|
||||
// imageUrl:
|
||||
// 'https://thronesapi.com/assets/images/robert-baratheon.jpeg',
|
||||
// text: '', firstName: '', lastName: '', title: '', family: '',
|
||||
// ),
|
||||
// ];
|
||||
// }
|
||||
// }
|
@ -1,21 +1,15 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class CardData {
|
||||
final String text;
|
||||
final String descriptionText;
|
||||
final IconData icon;
|
||||
final String? imageUrl;
|
||||
final String? firstName;
|
||||
final String? lastName;
|
||||
final String? fullName;
|
||||
final String? title;
|
||||
final String? family;
|
||||
final int? id;
|
||||
final String? id;
|
||||
|
||||
CardData({
|
||||
required this.text,
|
||||
required this.descriptionText,
|
||||
this.icon = Icons.people,
|
||||
this.imageUrl,
|
||||
required this.firstName,
|
||||
required this.lastName,
|
||||
|
@ -42,7 +42,7 @@ class DetailsPage extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
Text(
|
||||
data.descriptionText,
|
||||
data.text,
|
||||
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
|
||||
fontSize: 20.0,
|
||||
fontFamily: 'Times New Roman',
|
||||
|
@ -4,9 +4,7 @@ typedef OnLikeCallback = void Function(String? id, String title, bool isLiked)?;
|
||||
|
||||
class _Card extends StatelessWidget {
|
||||
final String text;
|
||||
final String descriptionText;
|
||||
final String? fullName;
|
||||
final IconData icon;
|
||||
final String? imageUrl;
|
||||
final OnLikeCallback onLike;
|
||||
final VoidCallback? onTap;
|
||||
@ -15,8 +13,6 @@ class _Card extends StatelessWidget {
|
||||
|
||||
const _Card(
|
||||
this.text, {
|
||||
this.icon = Icons.catching_pokemon,
|
||||
required this.descriptionText,
|
||||
required this.fullName,
|
||||
this.imageUrl,
|
||||
this.onLike,
|
||||
@ -33,9 +29,7 @@ class _Card extends StatelessWidget {
|
||||
}) =>
|
||||
_Card(
|
||||
data.text,
|
||||
descriptionText: data.descriptionText,
|
||||
fullName: data.fullName,
|
||||
icon: data.icon,
|
||||
imageUrl: data.imageUrl,
|
||||
onLike: onLike,
|
||||
onTap: onTap,
|
||||
@ -77,7 +71,7 @@ class _Card extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
Text(
|
||||
descriptionText,
|
||||
text,
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
],
|
||||
@ -86,14 +80,11 @@ class _Card extends StatelessWidget {
|
||||
Align(
|
||||
alignment: Alignment.bottomRight,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 8.0,
|
||||
right: 16.0,
|
||||
bottom: 16.0,
|
||||
),
|
||||
child: GestureDetector(
|
||||
onTap: () => onLike?.call(id, text, isLiked),
|
||||
child: AnimatedSwitcher(
|
||||
padding:
|
||||
const EdgeInsets.only(left: 8, right: 16, bottom: 16),
|
||||
child: GestureDetector(
|
||||
onTap: () => onLike?.call(id, fullName!, isLiked),
|
||||
child: AnimatedSwitcher(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
child: isLiked
|
||||
? const Icon(
|
||||
|
@ -14,20 +14,20 @@ class LikeBloc extends Bloc<LikeEvent, LikeState> {
|
||||
on<LoadLikesEvent>(_onLoadLikes);
|
||||
}
|
||||
|
||||
FutureOr<void> _onLoadLikes(LoadLikesEvent event, Emitter<LikeState> emit) async {
|
||||
Future<void> _onLoadLikes(LoadLikesEvent event, Emitter<LikeState> emit) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final data = prefs.getStringList(_likedPrefsKey);
|
||||
|
||||
emit(state.copyWith(likedIds: data));
|
||||
}
|
||||
|
||||
FutureOr<void> _onChangeLike(ChangeLikeEvent event, Emitter<LikeState> emit) async{
|
||||
Future<void> _onChangeLike(ChangeLikeEvent event, Emitter<LikeState> emit) async {
|
||||
final updatedList = List<String>.from(state.likedIds ?? []);
|
||||
|
||||
if (updatedList.contains(event.id.toString())) {
|
||||
updatedList.remove(event.id.toString());
|
||||
if (updatedList.contains(event.id)) {
|
||||
updatedList.remove(event.id);
|
||||
} else {
|
||||
updatedList.add(event.id.toString());
|
||||
updatedList.add(event.id);
|
||||
}
|
||||
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
|
Loading…
x
Reference in New Issue
Block a user