lab6 part 2 end
This commit is contained in:
parent
aa0c4a7f9d
commit
903878a412
@ -6,7 +6,8 @@ part 'characters_dto.g.dart';
|
|||||||
@JsonSerializable(createToJson: false)
|
@JsonSerializable(createToJson: false)
|
||||||
class CharactersDto{
|
class CharactersDto{
|
||||||
final List<CharactersDataDto>? data;
|
final List<CharactersDataDto>? data;
|
||||||
const CharactersDto({this.data});
|
final MetaDto? meta;
|
||||||
|
const CharactersDto({this.data, this.meta});
|
||||||
factory CharactersDto.fromJson(Map<String, dynamic> json) => _$CharactersDtoFromJson(json);
|
factory CharactersDto.fromJson(Map<String, dynamic> json) => _$CharactersDtoFromJson(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,3 +30,23 @@ class CharasterAttributesDataDto{
|
|||||||
const CharasterAttributesDataDto({this.name, this.born, this.died, this.image});
|
const CharasterAttributesDataDto({this.name, this.born, this.died, this.image});
|
||||||
factory CharasterAttributesDataDto.fromJson(Map<String, dynamic> json) => _$CharasterAttributesDataDtoFromJson(json);
|
factory CharasterAttributesDataDto.fromJson(Map<String, dynamic> json) => _$CharasterAttributesDataDtoFromJson(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);
|
||||||
|
}
|
@ -11,6 +11,9 @@ CharactersDto _$CharactersDtoFromJson(Map<String, dynamic> json) =>
|
|||||||
data: (json['data'] as List<dynamic>?)
|
data: (json['data'] as List<dynamic>?)
|
||||||
?.map((e) => CharactersDataDto.fromJson(e as Map<String, dynamic>))
|
?.map((e) => CharactersDataDto.fromJson(e as Map<String, dynamic>))
|
||||||
.toList(),
|
.toList(),
|
||||||
|
meta: json['meta'] == null
|
||||||
|
? null
|
||||||
|
: MetaDto.fromJson(json['meta'] as Map<String, dynamic>),
|
||||||
);
|
);
|
||||||
|
|
||||||
CharactersDataDto _$CharactersDataDtoFromJson(Map<String, dynamic> json) =>
|
CharactersDataDto _$CharactersDataDtoFromJson(Map<String, dynamic> json) =>
|
||||||
@ -31,3 +34,16 @@ CharasterAttributesDataDto _$CharasterAttributesDataDtoFromJson(
|
|||||||
died: json['died'] as String?,
|
died: json['died'] as String?,
|
||||||
image: json['image'] 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,5 +1,6 @@
|
|||||||
import 'package:pmd_lab/data/dtos/characters_dto.dart';
|
import 'package:pmd_lab/data/dtos/characters_dto.dart';
|
||||||
import 'package:pmd_lab/domain/models/card.dart';
|
import 'package:pmd_lab/domain/models/card.dart';
|
||||||
|
import 'package:pmd_lab/domain/models/home.dart';
|
||||||
|
|
||||||
|
|
||||||
const _imagePlaceholder = 'https://cdn-icons-png.flaticon.com/512/4054/4054617.png';
|
const _imagePlaceholder = 'https://cdn-icons-png.flaticon.com/512/4054/4054617.png';
|
||||||
@ -11,7 +12,6 @@ extension CharacterDataDtoToModel on CharactersDataDto {
|
|||||||
imgUrl: attributes?.image ?? _imagePlaceholder,
|
imgUrl: attributes?.image ?? _imagePlaceholder,
|
||||||
description: _makeDescription(attributes?.born, attributes?.died),
|
description: _makeDescription(attributes?.born, attributes?.died),
|
||||||
);
|
);
|
||||||
|
|
||||||
String _makeDescription(String? born, String? died){
|
String _makeDescription(String? born, String? died){
|
||||||
return born != null && died != null
|
return born != null && died != null
|
||||||
? '$born - $died'
|
? '$born - $died'
|
||||||
@ -22,3 +22,10 @@ extension CharacterDataDtoToModel on CharactersDataDto {
|
|||||||
: '';
|
: '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension CharactersDtoToModel on CharactersDto {
|
||||||
|
HomeData toDomain() => HomeData(
|
||||||
|
data: data?.map((e) => e.toDomain()).toList(),
|
||||||
|
nextPage: meta?.pagination?.next,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
8
lib/domain/models/home.dart
Normal file
8
lib/domain/models/home.dart
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import 'card.dart';
|
||||||
|
|
||||||
|
class HomeData {
|
||||||
|
final List<CardData>? data;
|
||||||
|
final int? nextPage;
|
||||||
|
|
||||||
|
HomeData({this.data, this.nextPage});
|
||||||
|
}
|
@ -11,13 +11,29 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onLoadData(HomeLoadDataEvent event, Emitter<HomeState> emit) async {
|
Future<void> _onLoadData(HomeLoadDataEvent event, Emitter<HomeState> emit) async {
|
||||||
|
if (event.nextPage == null) {
|
||||||
emit(state.copyWith(isLoading: true));
|
emit(state.copyWith(isLoading: true));
|
||||||
|
} else {
|
||||||
|
emit(state.copyWith(isPaginationLoading: true));
|
||||||
|
}
|
||||||
|
|
||||||
final data = await repo.loadData(q: event.search);
|
String? error;
|
||||||
|
|
||||||
|
final data = await repo.loadData(
|
||||||
|
q: event.search,
|
||||||
|
page: event.nextPage ?? 1,
|
||||||
|
onError: (e) => error = e,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (event.nextPage != null) {
|
||||||
|
data?.data?.insertAll(0, state.data?.data ?? []);
|
||||||
|
}
|
||||||
|
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
|
isPaginationLoading: false,
|
||||||
data: data,
|
data: data,
|
||||||
|
error: error,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,5 +5,7 @@ class HomeEvent {
|
|||||||
|
|
||||||
class HomeLoadDataEvent extends HomeEvent{
|
class HomeLoadDataEvent extends HomeEvent{
|
||||||
final String? search;
|
final String? search;
|
||||||
const HomeLoadDataEvent({this.search});
|
final int? nextPage;
|
||||||
|
const HomeLoadDataEvent({this.search, this.nextPage});
|
||||||
|
|
||||||
}
|
}
|
@ -1,29 +1,43 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:copy_with_extension/copy_with_extension.dart';
|
||||||
import 'package:pmd_lab/domain/models/card.dart';
|
import 'package:pmd_lab/domain/models/card.dart';
|
||||||
|
import 'package:pmd_lab/domain/models/home.dart';
|
||||||
|
|
||||||
|
part 'state.g.dart';
|
||||||
|
|
||||||
|
@CopyWith()
|
||||||
class HomeState extends Equatable {
|
class HomeState extends Equatable {
|
||||||
final List<CardData>? data;
|
final HomeData? data;
|
||||||
final bool isLoading;
|
final bool isLoading;
|
||||||
|
final bool isPaginationLoading;
|
||||||
|
final String? error;
|
||||||
|
|
||||||
const HomeState({
|
const HomeState({
|
||||||
this.data,
|
this.data,
|
||||||
this.isLoading = false,
|
this.isLoading = false,
|
||||||
|
this.isPaginationLoading = false,
|
||||||
|
this.error,
|
||||||
});
|
});
|
||||||
|
|
||||||
HomeState copyWith({
|
HomeState copyWith({
|
||||||
List<CardData>? data,
|
HomeData? data,
|
||||||
bool? isLoading,
|
bool? isLoading,
|
||||||
|
bool? isPaginationLoading,
|
||||||
|
String? error,
|
||||||
}) =>
|
}) =>
|
||||||
HomeState(
|
HomeState(
|
||||||
data: data ?? this.data,
|
data: data ?? this.data,
|
||||||
isLoading: isLoading ?? this.isLoading,
|
isLoading: isLoading ?? this.isLoading,
|
||||||
|
isPaginationLoading: isPaginationLoading ?? this.isPaginationLoading,
|
||||||
|
error: error ?? this.error,
|
||||||
);
|
);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [
|
List<Object?> get props => [
|
||||||
data,
|
data,
|
||||||
isLoading,
|
isLoading,
|
||||||
|
isPaginationLoading,
|
||||||
|
error,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
92
lib/presentation/home_page/bloc/state.g.dart
Normal file
92
lib/presentation/home_page/bloc/state.g.dart
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
|
|
||||||
|
part of 'state.dart';
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// CopyWithGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
abstract class _$HomeStateCWProxy {
|
||||||
|
HomeState data(HomeData? data);
|
||||||
|
|
||||||
|
HomeState isLoading(bool isLoading);
|
||||||
|
|
||||||
|
HomeState isPaginationLoading(bool isPaginationLoading);
|
||||||
|
|
||||||
|
HomeState error(String? error);
|
||||||
|
|
||||||
|
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `HomeState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
|
||||||
|
///
|
||||||
|
/// Usage
|
||||||
|
/// ```dart
|
||||||
|
/// HomeState(...).copyWith(id: 12, name: "My name")
|
||||||
|
/// ````
|
||||||
|
HomeState call({
|
||||||
|
HomeData? data,
|
||||||
|
bool? isLoading,
|
||||||
|
bool? isPaginationLoading,
|
||||||
|
String? error,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfHomeState.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfHomeState.copyWith.fieldName(...)`
|
||||||
|
class _$HomeStateCWProxyImpl implements _$HomeStateCWProxy {
|
||||||
|
const _$HomeStateCWProxyImpl(this._value);
|
||||||
|
|
||||||
|
final HomeState _value;
|
||||||
|
|
||||||
|
@override
|
||||||
|
HomeState data(HomeData? data) => this(data: data);
|
||||||
|
|
||||||
|
@override
|
||||||
|
HomeState isLoading(bool isLoading) => this(isLoading: isLoading);
|
||||||
|
|
||||||
|
@override
|
||||||
|
HomeState isPaginationLoading(bool isPaginationLoading) =>
|
||||||
|
this(isPaginationLoading: isPaginationLoading);
|
||||||
|
|
||||||
|
@override
|
||||||
|
HomeState error(String? error) => this(error: error);
|
||||||
|
|
||||||
|
@override
|
||||||
|
|
||||||
|
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `HomeState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
|
||||||
|
///
|
||||||
|
/// Usage
|
||||||
|
/// ```dart
|
||||||
|
/// HomeState(...).copyWith(id: 12, name: "My name")
|
||||||
|
/// ````
|
||||||
|
HomeState call({
|
||||||
|
Object? data = const $CopyWithPlaceholder(),
|
||||||
|
Object? isLoading = const $CopyWithPlaceholder(),
|
||||||
|
Object? isPaginationLoading = const $CopyWithPlaceholder(),
|
||||||
|
Object? error = const $CopyWithPlaceholder(),
|
||||||
|
}) {
|
||||||
|
return HomeState(
|
||||||
|
data: data == const $CopyWithPlaceholder()
|
||||||
|
? _value.data
|
||||||
|
// ignore: cast_nullable_to_non_nullable
|
||||||
|
: data as HomeData?,
|
||||||
|
isLoading: isLoading == const $CopyWithPlaceholder() || isLoading == null
|
||||||
|
? _value.isLoading
|
||||||
|
// ignore: cast_nullable_to_non_nullable
|
||||||
|
: isLoading as bool,
|
||||||
|
isPaginationLoading:
|
||||||
|
isPaginationLoading == const $CopyWithPlaceholder() ||
|
||||||
|
isPaginationLoading == null
|
||||||
|
? _value.isPaginationLoading
|
||||||
|
// ignore: cast_nullable_to_non_nullable
|
||||||
|
: isPaginationLoading as bool,
|
||||||
|
error: error == const $CopyWithPlaceholder()
|
||||||
|
? _value.error
|
||||||
|
// ignore: cast_nullable_to_non_nullable
|
||||||
|
: error as String?,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension $HomeStateCopyWith on HomeState {
|
||||||
|
/// Returns a callable class that can be used as follows: `instanceOfHomeState.copyWith(...)` or like so:`instanceOfHomeState.copyWith.fieldName(...)`.
|
||||||
|
// ignore: library_private_types_in_public_api
|
||||||
|
_$HomeStateCWProxy get copyWith => _$HomeStateCWProxyImpl(this);
|
||||||
|
}
|
@ -79,21 +79,35 @@ class Body extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _BodyState extends State<Body> {
|
class _BodyState extends State<Body> {
|
||||||
|
final searchController = TextEditingController();
|
||||||
|
final scrollController = ScrollController();
|
||||||
final ApiInterface repo = PotterRepository();
|
final ApiInterface repo = PotterRepository();
|
||||||
late Future<List<CardData>?> data = repo.loadData(q: null);
|
late Future<List<CardData>?> data;
|
||||||
final TextEditingController searchController = TextEditingController();
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
context.read<HomeBloc>().add(const HomeLoadDataEvent());
|
context.read<HomeBloc>().add(const HomeLoadDataEvent());
|
||||||
});
|
});
|
||||||
|
scrollController.addListener(_onNextPageListener);
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
void _onNextPageListener() {
|
||||||
|
if (scrollController.offset > scrollController.position.maxScrollExtent) {
|
||||||
|
final bloc = context.read<HomeBloc>();
|
||||||
|
if (!bloc.state.isPaginationLoading) {
|
||||||
|
bloc.add(HomeLoadDataEvent(
|
||||||
|
search: searchController.text,
|
||||||
|
nextPage: bloc.state.data?.nextPage,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@override
|
@override
|
||||||
void dispose(){
|
void dispose(){
|
||||||
searchController.dispose();
|
searchController.dispose();
|
||||||
|
scrollController.dispose();
|
||||||
|
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,16 +129,21 @@ class _BodyState extends State<Body> {
|
|||||||
),
|
),
|
||||||
|
|
||||||
BlocBuilder<HomeBloc, HomeState>(
|
BlocBuilder<HomeBloc, HomeState>(
|
||||||
builder: (context, state) => state.isLoading
|
builder: (context, state) => state.error != null
|
||||||
|
? Text(
|
||||||
|
state.error ?? '',
|
||||||
|
style: Theme.of(context).textTheme.headlineSmall?.copyWith(color: Colors.red),
|
||||||
|
)
|
||||||
|
: state.isLoading
|
||||||
? const CircularProgressIndicator()
|
? const CircularProgressIndicator()
|
||||||
: Expanded(
|
: Expanded(
|
||||||
child: RefreshIndicator(
|
child: RefreshIndicator(
|
||||||
onRefresh: _onRefresh,
|
onRefresh: _onRefresh,
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
itemCount: state.data?.length ?? 0,
|
itemCount: state.data?.data?.length ?? 0,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final data = state.data?[index];
|
final data = state.data?.data?[index];
|
||||||
return data != null
|
return data != null
|
||||||
? _Card.fromData(
|
? _Card.fromData(
|
||||||
data,
|
data,
|
||||||
@ -137,7 +156,11 @@ class _BodyState extends State<Body> {
|
|||||||
), // RefreshIndicator
|
), // RefreshIndicator
|
||||||
), // Expanded
|
), // Expanded
|
||||||
), // BlocBuilder
|
), // BlocBuilder
|
||||||
|
BlocBuilder<HomeBloc, HomeState>(
|
||||||
|
builder: (context, state) => state.isPaginationLoading
|
||||||
|
? const CircularProgressIndicator()
|
||||||
|
: const SizedBox.shrink(),
|
||||||
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
import 'package:pmd_lab/domain/models/card.dart';
|
|
||||||
|
import 'package:pmd_lab/domain/models/home.dart';
|
||||||
|
|
||||||
|
typedef OnErrorCallback = void Function(String? error);
|
||||||
|
|
||||||
abstract class ApiInterface {
|
abstract class ApiInterface {
|
||||||
Future<List<CardData>?> loadData({String? q});
|
Future<HomeData?> loadData({OnErrorCallback? onError});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,28 +1,30 @@
|
|||||||
|
import 'package:pmd_lab/domain/models/home.dart';
|
||||||
import 'package:pmd_lab/repositories/api_interface.dart';
|
import 'package:pmd_lab/repositories/api_interface.dart';
|
||||||
import 'package:pmd_lab/domain/models/card.dart';
|
import 'package:pmd_lab/domain/models/card.dart';
|
||||||
|
|
||||||
class MockRepository extends ApiInterface {
|
class MockRepository extends ApiInterface {
|
||||||
@override
|
@override
|
||||||
Future <List<CardData>?> loadData({String? q}) async {
|
Future <HomeData?> loadData({OnErrorCallback? onError}) async {
|
||||||
return [
|
return HomeData();
|
||||||
CardData(
|
// return [
|
||||||
'Какая-то новость',
|
// CardData(
|
||||||
description: 'В данном блоке рекомендуем разместить краткую информацию',
|
// 'Какая-то новость',
|
||||||
imgUrl:
|
// description: 'В данном блоке рекомендуем разместить краткую информацию',
|
||||||
'https://universal.revengel.ru/assets/cache_image/images/services/3_731x487_1cb.png',
|
// imgUrl:
|
||||||
),
|
// 'https://universal.revengel.ru/assets/cache_image/images/services/3_731x487_1cb.png',
|
||||||
CardData(
|
// ),
|
||||||
'Ещё какая-то новость',
|
// CardData(
|
||||||
description: 'В данном блоке рекомендуем разместить краткую информацию',
|
// 'Ещё какая-то новость',
|
||||||
imgUrl:
|
// description: 'В данном блоке рекомендуем разместить краткую информацию',
|
||||||
"https://universal.revengel.ru/assets/cache_image/images/services/2_731x487_1cb.png",
|
// imgUrl:
|
||||||
),
|
// "https://universal.revengel.ru/assets/cache_image/images/services/2_731x487_1cb.png",
|
||||||
CardData(
|
// ),
|
||||||
'Ещё одна новость',
|
// CardData(
|
||||||
description: 'В данном блоке рекомендуем разместить краткую информацию',
|
// 'Ещё одна новость',
|
||||||
imgUrl:
|
// description: 'В данном блоке рекомендуем разместить краткую информацию',
|
||||||
"https://universal.revengel.ru/assets/cache_image/images/services/1_731x487_1cb.png",
|
// imgUrl:
|
||||||
)
|
// "https://universal.revengel.ru/assets/cache_image/images/services/1_731x487_1cb.png",
|
||||||
];
|
// )
|
||||||
|
//];
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,6 +4,7 @@ import 'package:dio/dio.dart';
|
|||||||
import 'package:pmd_lab/data/dtos/characters_dto.dart';
|
import 'package:pmd_lab/data/dtos/characters_dto.dart';
|
||||||
import 'package:pmd_lab/data/mappes/characters_mapper.dart';
|
import 'package:pmd_lab/data/mappes/characters_mapper.dart';
|
||||||
import 'package:pmd_lab/domain/models/card.dart';
|
import 'package:pmd_lab/domain/models/card.dart';
|
||||||
|
import 'package:pmd_lab/domain/models/home.dart';
|
||||||
import 'package:pmd_lab/repositories/api_interface.dart';
|
import 'package:pmd_lab/repositories/api_interface.dart';
|
||||||
import 'package:pretty_dio_logger/pretty_dio_logger.dart';
|
import 'package:pretty_dio_logger/pretty_dio_logger.dart';
|
||||||
|
|
||||||
@ -17,22 +18,30 @@ class PotterRepository extends ApiInterface{
|
|||||||
static const String _baseUrl = 'https://api.potterdb.com';
|
static const String _baseUrl = 'https://api.potterdb.com';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<CardData>?> loadData({String? q}) async {
|
Future<HomeData?> loadData({
|
||||||
try{
|
OnErrorCallback? onError,
|
||||||
|
String? q,
|
||||||
|
int page = 1,
|
||||||
|
int pageSize = 25,
|
||||||
|
}) async {
|
||||||
|
try {
|
||||||
const String url = '$_baseUrl/v1/characters';
|
const String url = '$_baseUrl/v1/characters';
|
||||||
|
|
||||||
final Response<dynamic> response = await _dio.get<Map<dynamic, dynamic>>(
|
final Response<dynamic> response = await _dio.get<Map<dynamic, dynamic>>(
|
||||||
url,
|
url,
|
||||||
queryParameters: q != null ? {"filter[name_cont]": q} : null,
|
queryParameters: {
|
||||||
|
'filter[name_cont]': q,
|
||||||
|
'page[number]': page,
|
||||||
|
'page[size]': pageSize,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
final CharactersDto dto = CharactersDto.fromJson(response.data as Map<String, dynamic>);
|
final CharactersDto dto = CharactersDto.fromJson(response.data as Map<String, dynamic>);
|
||||||
final List<CardData>? data = dto.data?.map((e) => e.toDomain()).toList();
|
final HomeData data = dto.toDomain();
|
||||||
return data;
|
return data;
|
||||||
|
|
||||||
}
|
} on DioException catch (e) {
|
||||||
on DioException catch (e) {
|
onError?.call(e.error?.toString());
|
||||||
log("DioException: $e");
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
16
pubspec.lock
16
pubspec.lock
@ -166,6 +166,22 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.1.2"
|
version: "3.1.2"
|
||||||
|
copy_with_extension:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: copy_with_extension
|
||||||
|
sha256: fbcf890b0c34aedf0894f91a11a579994b61b4e04080204656b582708b5b1125
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "5.0.4"
|
||||||
|
copy_with_extension_gen:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: copy_with_extension_gen
|
||||||
|
sha256: "51cd11094096d40824c8da629ca7f16f3b7cea5fc44132b679617483d43346b0"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "5.0.4"
|
||||||
crypto:
|
crypto:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -41,7 +41,7 @@ dependencies:
|
|||||||
|
|
||||||
equatable: ^2.0.5
|
equatable: ^2.0.5
|
||||||
flutter_bloc: ^8.1.5
|
flutter_bloc: ^8.1.5
|
||||||
|
copy_with_extension_gen: ^5.0.4
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
Loading…
x
Reference in New Issue
Block a user