мини-правки
This commit is contained in:
parent
a9f46e02db
commit
e322c413b8
@ -1,60 +0,0 @@
|
|||||||
import 'package:json_annotation/json_annotation.dart';
|
|
||||||
|
|
||||||
part 'characters_dto.g.dart';
|
|
||||||
|
|
||||||
@JsonSerializable(createToJson: false)
|
|
||||||
class CharactersDto {
|
|
||||||
final List<CharacterDataDto>? data;
|
|
||||||
final MetaDto? meta;
|
|
||||||
|
|
||||||
const CharactersDto({
|
|
||||||
this.data,
|
|
||||||
this.meta,
|
|
||||||
});
|
|
||||||
|
|
||||||
factory CharactersDto.fromJson(Map<String, dynamic> json) => _$CharactersDtoFromJson(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
@JsonSerializable(createToJson: false)
|
|
||||||
class CharacterDataDto {
|
|
||||||
final String? id;
|
|
||||||
final String? type;
|
|
||||||
final CharacterAttributesDataDto? attributes;
|
|
||||||
|
|
||||||
const CharacterDataDto({this.id, this.type, this.attributes});
|
|
||||||
|
|
||||||
factory CharacterDataDto.fromJson(Map<String, dynamic> json) => _$CharacterDataDtoFromJson(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
@JsonSerializable(createToJson: false)
|
|
||||||
class CharacterAttributesDataDto {
|
|
||||||
final String? name;
|
|
||||||
final String? born;
|
|
||||||
final String? died;
|
|
||||||
final String? image;
|
|
||||||
|
|
||||||
const CharacterAttributesDataDto({this.name, this.born, this.died, this.image});
|
|
||||||
|
|
||||||
factory CharacterAttributesDataDto.fromJson(Map<String, dynamic> json) =>
|
|
||||||
_$CharacterAttributesDataDtoFromJson(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
@JsonSerializable(createToJson: false)
|
|
||||||
class MetaDto {
|
|
||||||
final PaginationDto? pagination;
|
|
||||||
|
|
||||||
const MetaDto({this.pagination});
|
|
||||||
|
|
||||||
factory MetaDto.fromJson(Map<String, dynamic> json) => _$MetaDtoFromJson(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
@JsonSerializable(createToJson: false)
|
|
||||||
class PaginationDto {
|
|
||||||
final int? current;
|
|
||||||
final int? next;
|
|
||||||
final int? last;
|
|
||||||
|
|
||||||
const PaginationDto({this.current, this.next, this.last});
|
|
||||||
|
|
||||||
factory PaginationDto.fromJson(Map<String, dynamic> json) => _$PaginationDtoFromJson(json);
|
|
||||||
}
|
|
@ -1,49 +0,0 @@
|
|||||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
|
||||||
|
|
||||||
part of 'characters_dto.dart';
|
|
||||||
|
|
||||||
// **************************************************************************
|
|
||||||
// JsonSerializableGenerator
|
|
||||||
// **************************************************************************
|
|
||||||
|
|
||||||
CharactersDto _$CharactersDtoFromJson(Map<String, dynamic> json) =>
|
|
||||||
CharactersDto(
|
|
||||||
data: (json['data'] as List<dynamic>?)
|
|
||||||
?.map((e) => CharacterDataDto.fromJson(e as Map<String, dynamic>))
|
|
||||||
.toList(),
|
|
||||||
meta: json['meta'] == null
|
|
||||||
? null
|
|
||||||
: MetaDto.fromJson(json['meta'] as Map<String, dynamic>),
|
|
||||||
);
|
|
||||||
|
|
||||||
CharacterDataDto _$CharacterDataDtoFromJson(Map<String, dynamic> json) =>
|
|
||||||
CharacterDataDto(
|
|
||||||
id: json['id'] as String?,
|
|
||||||
type: json['type'] as String?,
|
|
||||||
attributes: json['attributes'] == null
|
|
||||||
? null
|
|
||||||
: CharacterAttributesDataDto.fromJson(
|
|
||||||
json['attributes'] as Map<String, dynamic>),
|
|
||||||
);
|
|
||||||
|
|
||||||
CharacterAttributesDataDto _$CharacterAttributesDataDtoFromJson(
|
|
||||||
Map<String, dynamic> json) =>
|
|
||||||
CharacterAttributesDataDto(
|
|
||||||
name: json['name'] as String?,
|
|
||||||
born: json['born'] as String?,
|
|
||||||
died: json['died'] as String?,
|
|
||||||
image: json['image'] as String?,
|
|
||||||
);
|
|
||||||
|
|
||||||
MetaDto _$MetaDtoFromJson(Map<String, dynamic> json) => MetaDto(
|
|
||||||
pagination: json['pagination'] == null
|
|
||||||
? null
|
|
||||||
: PaginationDto.fromJson(json['pagination'] as Map<String, dynamic>),
|
|
||||||
);
|
|
||||||
|
|
||||||
PaginationDto _$PaginationDtoFromJson(Map<String, dynamic> json) =>
|
|
||||||
PaginationDto(
|
|
||||||
current: (json['current'] as num?)?.toInt(),
|
|
||||||
next: (json['next'] as num?)?.toInt(),
|
|
||||||
last: (json['last'] as num?)?.toInt(),
|
|
||||||
);
|
|
@ -1,34 +0,0 @@
|
|||||||
import 'package:project1/data/dtos/characters_dto.dart';
|
|
||||||
import 'package:project1/domain/models/card.dart';
|
|
||||||
|
|
||||||
import '../../domain/models/home.dart';
|
|
||||||
|
|
||||||
const _imagePlaceholder =
|
|
||||||
'https://upload.wikimedia.org/wikipedia/en/archive/b/b1/20210811082420%21Portrait_placeholder.png';
|
|
||||||
|
|
||||||
extension CharactersDtoToModel on CharactersDto {
|
|
||||||
HomeData toDomain() => HomeData(
|
|
||||||
data: data?.map((e) => e.toDomain()).toList(),
|
|
||||||
nextPage: meta?.pagination?.next,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
extension CharacterDataDtoToModel on CharacterDataDto {
|
|
||||||
CardData toDomain() => CardData(
|
|
||||||
attributes?.name ?? 'UNKNOWN',
|
|
||||||
imageUrl: attributes?.image ?? _imagePlaceholder,
|
|
||||||
descriptionText:
|
|
||||||
_makeDescriptionText(attributes?.born, attributes?.died),
|
|
||||||
id: id,
|
|
||||||
);
|
|
||||||
|
|
||||||
String _makeDescriptionText(String? born, String? died) {
|
|
||||||
return born != null && died != null
|
|
||||||
? '$born - $died'
|
|
||||||
: born != null
|
|
||||||
? 'born: $born'
|
|
||||||
: died != null
|
|
||||||
? 'died: $died'
|
|
||||||
: '';
|
|
||||||
}
|
|
||||||
}
|
|
@ -17,14 +17,12 @@ class MockRepository extends ApiInterface {
|
|||||||
CardData(
|
CardData(
|
||||||
'Hi',
|
'Hi',
|
||||||
descriptionText: 'pretty face',
|
descriptionText: 'pretty face',
|
||||||
icon: Icons.hail,
|
|
||||||
imageUrl:
|
imageUrl:
|
||||||
'https://www.thesprucepets.com/thmb/nKNaS4I586B_H7sEUw9QAXvWM_0=/2121x0/filters:no_upscale():strip_icc()/GettyImages-135630198-5ba7d225c9e77c0050cff91b.jpg',
|
'https://www.thesprucepets.com/thmb/nKNaS4I586B_H7sEUw9QAXvWM_0=/2121x0/filters:no_upscale():strip_icc()/GettyImages-135630198-5ba7d225c9e77c0050cff91b.jpg',
|
||||||
),
|
),
|
||||||
CardData(
|
CardData(
|
||||||
'Orange',
|
'Orange',
|
||||||
descriptionText: 'I like autumn',
|
descriptionText: 'I like autumn',
|
||||||
icon: Icons.warning_amber,
|
|
||||||
imageUrl: 'https://furmanagers.com/wp-content/uploads/2019/11/dreamstime_l_22075357.jpg',
|
imageUrl: 'https://furmanagers.com/wp-content/uploads/2019/11/dreamstime_l_22075357.jpg',
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
import 'package:dio/dio.dart';
|
|
||||||
import 'package:project1/data/dtos/characters_dto.dart';
|
|
||||||
import 'package:project1/data/mappers/characters_mapper.dart';
|
|
||||||
import 'package:project1/data/repositories/api_interface.dart';
|
|
||||||
import 'package:project1/domain/models/card.dart';
|
|
||||||
import 'package:project1/domain/models/home.dart';
|
|
||||||
import 'package:project1/presentation/home_page/bloc/events.dart';
|
|
||||||
import 'package:pretty_dio_logger/pretty_dio_logger.dart';
|
|
||||||
|
|
||||||
class PotterRepository extends ApiInterface {
|
|
||||||
static final Dio _dio = Dio()
|
|
||||||
..interceptors.add(PrettyDioLogger(
|
|
||||||
requestHeader: true,
|
|
||||||
requestBody: true,
|
|
||||||
));
|
|
||||||
|
|
||||||
static const String _baseUrl = 'https://api.potterdb.com';
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<HomeData?> loadData({
|
|
||||||
OnErrorCallback? onError,
|
|
||||||
String? q,
|
|
||||||
int page = 1,
|
|
||||||
int pageSize = 7,
|
|
||||||
}) async {
|
|
||||||
try {
|
|
||||||
const String url = '$_baseUrl/v1/characters';
|
|
||||||
|
|
||||||
final Response<dynamic> response = await _dio.get<Map<dynamic, dynamic>>(
|
|
||||||
url,
|
|
||||||
queryParameters: {
|
|
||||||
'filter[name_cont]': q,
|
|
||||||
'page[number]': page,
|
|
||||||
'page[size]': pageSize,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
final CharactersDto dto = CharactersDto.fromJson(response.data as Map<String, dynamic>);
|
|
||||||
final HomeData data = dto.toDomain();
|
|
||||||
return data;
|
|
||||||
} on DioException catch (e) {
|
|
||||||
onError?.call(e.error?.toString());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,14 +3,12 @@ import 'package:flutter/material.dart';
|
|||||||
class CardData {
|
class CardData {
|
||||||
final String text;
|
final String text;
|
||||||
final String descriptionText;
|
final String descriptionText;
|
||||||
final IconData icon;
|
|
||||||
final String? imageUrl;
|
final String? imageUrl;
|
||||||
final String? id;
|
final String? id;
|
||||||
|
|
||||||
CardData(
|
CardData(
|
||||||
this.text, {
|
this.text, {
|
||||||
required this.descriptionText,
|
required this.descriptionText,
|
||||||
this.icon = Icons.cake,
|
|
||||||
this.imageUrl,
|
this.imageUrl,
|
||||||
this.id,
|
this.id,
|
||||||
});
|
});
|
||||||
|
@ -9,7 +9,6 @@ import 'package:project1/presentation/locale_bloc/locale_bloc.dart';
|
|||||||
import 'package:project1/presentation/locale_bloc/locale_state.dart';
|
import 'package:project1/presentation/locale_bloc/locale_state.dart';
|
||||||
import 'components/locale/l10n/app_locale.dart';
|
import 'components/locale/l10n/app_locale.dart';
|
||||||
import 'data/repositories/films_repository.dart';
|
import 'data/repositories/films_repository.dart';
|
||||||
import 'data/repositories/potter_repository.dart';
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(const MyApp());
|
runApp(const MyApp());
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:project1/data/repositories/potter_repository.dart';
|
|
||||||
import 'package:project1/presentation/home_page/bloc/events.dart';
|
import 'package:project1/presentation/home_page/bloc/events.dart';
|
||||||
import 'package:project1/presentation/home_page/bloc/state.dart';
|
import 'package:project1/presentation/home_page/bloc/state.dart';
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ typedef OnLikeCallback = void Function(String? id, String title, bool isLiked)?;
|
|||||||
class _Card extends StatelessWidget {
|
class _Card extends StatelessWidget {
|
||||||
final String text;
|
final String text;
|
||||||
final String descriptionText;
|
final String descriptionText;
|
||||||
final IconData icon;
|
|
||||||
final String? imageUrl;
|
final String? imageUrl;
|
||||||
final OnLikeCallback onLike;
|
final OnLikeCallback onLike;
|
||||||
final VoidCallback? onTap;
|
final VoidCallback? onTap;
|
||||||
@ -14,7 +13,6 @@ class _Card extends StatelessWidget {
|
|||||||
|
|
||||||
const _Card(
|
const _Card(
|
||||||
this.text, {
|
this.text, {
|
||||||
this.icon = Icons.ac_unit_outlined,
|
|
||||||
required this.descriptionText,
|
required this.descriptionText,
|
||||||
this.imageUrl,
|
this.imageUrl,
|
||||||
this.onLike,
|
this.onLike,
|
||||||
@ -32,7 +30,6 @@ class _Card extends StatelessWidget {
|
|||||||
_Card(
|
_Card(
|
||||||
data.text,
|
data.text,
|
||||||
descriptionText: data.descriptionText,
|
descriptionText: data.descriptionText,
|
||||||
icon: data.icon,
|
|
||||||
imageUrl: data.imageUrl,
|
imageUrl: data.imageUrl,
|
||||||
onLike: onLike,
|
onLike: onLike,
|
||||||
onTap: onTap,
|
onTap: onTap,
|
||||||
|
@ -3,7 +3,6 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:project1/components/extensions/context_x.dart';
|
import 'package:project1/components/extensions/context_x.dart';
|
||||||
import 'package:project1/components/utils/debounce.dart';
|
import 'package:project1/components/utils/debounce.dart';
|
||||||
import 'package:project1/data/repositories/potter_repository.dart';
|
|
||||||
import 'package:project1/domain/models/card.dart';
|
import 'package:project1/domain/models/card.dart';
|
||||||
import 'package:project1/main.dart';
|
import 'package:project1/main.dart';
|
||||||
import 'package:project1/presentation/details_page/details_page.dart';
|
import 'package:project1/presentation/details_page/details_page.dart';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user