Compare commits
6 Commits
d2237434ee
...
bebc4de8af
Author | SHA1 | Date | |
---|---|---|---|
|
bebc4de8af | ||
|
c83f11ad7c | ||
|
302cbf28f4 | ||
|
90808f51aa | ||
|
63aa49af9d | ||
|
386c3087b0 |
5
Makefile
5
Makefile
@ -4,11 +4,6 @@ gen:
|
|||||||
icon:
|
icon:
|
||||||
flutter pub run flutter_launcher_icons:main
|
flutter pub run flutter_launcher_icons:main
|
||||||
|
|
||||||
hello:
|
|
||||||
echo "Hi!"; \
|
|
||||||
echo "I`m makefile"; \
|
|
||||||
echo "^_^"
|
|
||||||
|
|
||||||
init_res:
|
init_res:
|
||||||
dart pub global activate flutter_asset_generator
|
dart pub global activate flutter_asset_generator
|
||||||
|
|
||||||
|
@ -1,53 +0,0 @@
|
|||||||
import 'package:json_annotation/json_annotation.dart';
|
|
||||||
|
|
||||||
part 'characters_dto.g.dart';
|
|
||||||
|
|
||||||
@JsonSerializable(createToJson: false)
|
|
||||||
class CharactersDto {
|
|
||||||
final List<CharactersDataDto>? data;
|
|
||||||
final MetaDto? meta;
|
|
||||||
const CharactersDto({this.data, this.meta});
|
|
||||||
factory CharactersDto.fromJson(Map<String, dynamic> json) => _$CharactersDtoFromJson(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
@JsonSerializable(createToJson: false)
|
|
||||||
class CharactersDataDto {
|
|
||||||
final String? id;
|
|
||||||
final String? type;
|
|
||||||
final CharasterAttributesDataDto? attributes;
|
|
||||||
const CharactersDataDto({this.id, this.type, this.attributes});
|
|
||||||
factory CharactersDataDto.fromJson(Map<String, dynamic> json) =>
|
|
||||||
_$CharactersDataDtoFromJson(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
@JsonSerializable(createToJson: false)
|
|
||||||
class CharasterAttributesDataDto {
|
|
||||||
final String? name;
|
|
||||||
final String? born;
|
|
||||||
final String? died;
|
|
||||||
final String? image;
|
|
||||||
|
|
||||||
const CharasterAttributesDataDto({this.name, this.born, this.died, this.image});
|
|
||||||
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);
|
|
||||||
}
|
|
@ -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) => CharactersDataDto.fromJson(e as Map<String, dynamic>))
|
|
||||||
.toList(),
|
|
||||||
meta: json['meta'] == null
|
|
||||||
? null
|
|
||||||
: MetaDto.fromJson(json['meta'] as Map<String, dynamic>),
|
|
||||||
);
|
|
||||||
|
|
||||||
CharactersDataDto _$CharactersDataDtoFromJson(Map<String, dynamic> json) =>
|
|
||||||
CharactersDataDto(
|
|
||||||
id: json['id'] as String?,
|
|
||||||
type: json['type'] as String?,
|
|
||||||
attributes: json['attributes'] == null
|
|
||||||
? null
|
|
||||||
: CharasterAttributesDataDto.fromJson(
|
|
||||||
json['attributes'] as Map<String, dynamic>),
|
|
||||||
);
|
|
||||||
|
|
||||||
CharasterAttributesDataDto _$CharasterAttributesDataDtoFromJson(
|
|
||||||
Map<String, dynamic> json) =>
|
|
||||||
CharasterAttributesDataDto(
|
|
||||||
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(),
|
|
||||||
);
|
|
23
lib/data/dtos/titans_dto.dart
Normal file
23
lib/data/dtos/titans_dto.dart
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import 'package:json_annotation/json_annotation.dart';
|
||||||
|
|
||||||
|
part 'titans_dto.g.dart';
|
||||||
|
|
||||||
|
@JsonSerializable(createToJson: false)
|
||||||
|
class TitansDto {
|
||||||
|
final List<TitansResultsDto>? results;
|
||||||
|
const TitansDto({this.results});
|
||||||
|
factory TitansDto.fromJson(Map<String, dynamic> json) => _$TitansDtoFromJson(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonSerializable(createToJson: false)
|
||||||
|
class TitansResultsDto {
|
||||||
|
final int? id;
|
||||||
|
final String? name;
|
||||||
|
final String? height;
|
||||||
|
final List<String>? abilities;
|
||||||
|
final String? allegiance;
|
||||||
|
final String? img;
|
||||||
|
const TitansResultsDto({this.id, this.name, this.height, this.abilities, this.allegiance, this.img});
|
||||||
|
factory TitansResultsDto.fromJson(Map<String, dynamic> json) =>
|
||||||
|
_$TitansResultsDtoFromJson(json);
|
||||||
|
}
|
25
lib/data/dtos/titans_dto.g.dart
Normal file
25
lib/data/dtos/titans_dto.g.dart
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
|
|
||||||
|
part of 'titans_dto.dart';
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// JsonSerializableGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
TitansDto _$TitansDtoFromJson(Map<String, dynamic> json) => TitansDto(
|
||||||
|
results: (json['results'] as List<dynamic>?)
|
||||||
|
?.map((e) => TitansResultsDto.fromJson(e as Map<String, dynamic>))
|
||||||
|
.toList(),
|
||||||
|
);
|
||||||
|
|
||||||
|
TitansResultsDto _$TitansResultsDtoFromJson(Map<String, dynamic> json) =>
|
||||||
|
TitansResultsDto(
|
||||||
|
id: (json['id'] as num?)?.toInt(),
|
||||||
|
name: json['name'] as String?,
|
||||||
|
height: json['height'] as String?,
|
||||||
|
abilities: (json['abilities'] as List<dynamic>?)
|
||||||
|
?.map((e) => e as String)
|
||||||
|
.toList(),
|
||||||
|
allegiance: json['allegiance'] as String?,
|
||||||
|
img: json['img'] as String?,
|
||||||
|
);
|
@ -1,30 +0,0 @@
|
|||||||
import 'package:pmd_lab/data/dtos/characters_dto.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';
|
|
||||||
|
|
||||||
extension CharacterDataDtoToModel on CharactersDataDto {
|
|
||||||
CardData toDomain() => CardData(
|
|
||||||
attributes?.name ?? 'UNKNOWN',
|
|
||||||
imgUrl: attributes?.image ?? _imagePlaceholder,
|
|
||||||
description: _makeDescription(attributes?.born, attributes?.died),
|
|
||||||
id: id,
|
|
||||||
);
|
|
||||||
String _makeDescription(String? born, String? died) {
|
|
||||||
return born != null && died != null
|
|
||||||
? '$born - $died'
|
|
||||||
: born != null
|
|
||||||
? 'born: $born'
|
|
||||||
: died != null
|
|
||||||
? 'died: $died'
|
|
||||||
: '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extension CharactersDtoToModel on CharactersDto {
|
|
||||||
HomeData toDomain() => HomeData(
|
|
||||||
data: data?.map((e) => e.toDomain()).toList(),
|
|
||||||
nextPage: meta?.pagination?.next,
|
|
||||||
);
|
|
||||||
}
|
|
27
lib/data/mappes/titans_mapper.dart
Normal file
27
lib/data/mappes/titans_mapper.dart
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import 'package:pmd_lab/data/dtos/titans_dto.dart';
|
||||||
|
import 'package:pmd_lab/domain/models/card.dart';
|
||||||
|
|
||||||
|
const _imagePlaceholder = 'https://cdn-icons-png.flaticon.com/512/4054/4054617.png';
|
||||||
|
|
||||||
|
extension CharacterDataDtoToModel on TitansResultsDto {
|
||||||
|
CardData toDomain() => CardData(
|
||||||
|
name ?? 'UNKNOWN',
|
||||||
|
img: img ?? _imagePlaceholder,
|
||||||
|
description: _makeDescription(height, abilities, allegiance),
|
||||||
|
id: id.toString(),
|
||||||
|
);
|
||||||
|
String _makeDescription(String? height, List<String>? abilities, String? allegiance) {
|
||||||
|
List<String> descriptionParts = [];
|
||||||
|
if (height != null && height.isNotEmpty) {
|
||||||
|
descriptionParts.add('Height: $height');
|
||||||
|
}
|
||||||
|
if (allegiance != null && allegiance.isNotEmpty) {
|
||||||
|
descriptionParts.add('Allegiance: $allegiance');
|
||||||
|
}
|
||||||
|
if (abilities != null && abilities.isNotEmpty) {
|
||||||
|
final abilitiesStr = abilities.join(', ');
|
||||||
|
descriptionParts.add('Abilities: $abilitiesStr.');
|
||||||
|
}
|
||||||
|
return descriptionParts.join('\n');
|
||||||
|
}
|
||||||
|
}
|
@ -1,13 +1,13 @@
|
|||||||
class CardData {
|
class CardData {
|
||||||
final String text;
|
final String name;
|
||||||
final String description;
|
final String description;
|
||||||
final String? imgUrl;
|
final String? img;
|
||||||
final String? id;
|
final String? id;
|
||||||
|
|
||||||
CardData(
|
CardData(
|
||||||
this.text, {
|
this.name, {
|
||||||
required this.description,
|
required this.description,
|
||||||
this.imgUrl,
|
this.img,
|
||||||
this.id,
|
this.id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
import 'card.dart';
|
|
||||||
|
|
||||||
class HomeData {
|
|
||||||
final List<CardData>? data;
|
|
||||||
final int? nextPage;
|
|
||||||
|
|
||||||
HomeData({this.data, this.nextPage});
|
|
||||||
}
|
|
@ -9,7 +9,8 @@ import 'package:pmd_lab/presentation/home_page/home_page.dart';
|
|||||||
import 'package:pmd_lab/presentation/like_bloc/like_bloc.dart';
|
import 'package:pmd_lab/presentation/like_bloc/like_bloc.dart';
|
||||||
import 'package:pmd_lab/presentation/locale_bloc/locale_bloc.dart';
|
import 'package:pmd_lab/presentation/locale_bloc/locale_bloc.dart';
|
||||||
import 'package:pmd_lab/presentation/locale_bloc/locale_state.dart';
|
import 'package:pmd_lab/presentation/locale_bloc/locale_state.dart';
|
||||||
import 'package:pmd_lab/repositories/potter_repository.dart';
|
import 'package:pmd_lab/repositories/mock_repository.dart';
|
||||||
|
import 'package:pmd_lab/repositories/titans_repository.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(const MyApp());
|
runApp(const MyApp());
|
||||||
@ -26,24 +27,23 @@ class MyApp extends StatelessWidget {
|
|||||||
child: BlocBuilder<LocaleBloc, LocaleState>(
|
child: BlocBuilder<LocaleBloc, LocaleState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
title: 'Potter App',
|
|
||||||
locale: state.currentLocale,
|
locale: state.currentLocale,
|
||||||
localizationsDelegates: AppLocale.localizationsDelegates,
|
localizationsDelegates: AppLocale.localizationsDelegates,
|
||||||
supportedLocales: AppLocale.supportedLocales,
|
supportedLocales: AppLocale.supportedLocales,
|
||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
primarySwatch: Colors.orange,
|
primarySwatch: Colors.orange,
|
||||||
scaffoldBackgroundColor: Colors.white,
|
scaffoldBackgroundColor: Color(0x33BDBCBC),
|
||||||
useMaterial3: true,
|
useMaterial3: true,
|
||||||
),
|
),
|
||||||
home: RepositoryProvider<PotterRepository>(
|
home: RepositoryProvider<TitansRepository>(
|
||||||
lazy: true,
|
lazy: true,
|
||||||
create: (_) => PotterRepository(),
|
create: (_) => TitansRepository(),
|
||||||
child: BlocProvider<LikeBloc>(
|
child: BlocProvider<LikeBloc>(
|
||||||
lazy: false,
|
lazy: false,
|
||||||
create: (context) => LikeBloc(),
|
create: (context) => LikeBloc(),
|
||||||
child: BlocProvider<HomeBloc>(
|
child: BlocProvider<HomeBloc>(
|
||||||
lazy: false,
|
lazy: false,
|
||||||
create: (context) => HomeBloc(context.read<PotterRepository>()),
|
create: (context) => HomeBloc(context.read<TitansRepository>()),
|
||||||
child: const MyHomePage(),
|
child: const MyHomePage(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:pmd_lab/domain/models/card.dart';
|
import 'package:pmd_lab/domain/models/card.dart';
|
||||||
|
|
||||||
class DetailsPage extends StatelessWidget {
|
class DetailsPage extends StatelessWidget {
|
||||||
@ -9,28 +10,59 @@ class DetailsPage extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(),
|
backgroundColor: Color(0xFF272727),
|
||||||
|
appBar: AppBar(
|
||||||
|
backgroundColor: const Color(0xFF272727), // Тёмный фон AppBar
|
||||||
|
iconTheme: const IconThemeData(
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
|
title: const Text(
|
||||||
|
'Детальная страница',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
elevation: 0,
|
||||||
|
systemOverlayStyle: SystemUiOverlayStyle.light,
|
||||||
|
),
|
||||||
body: Column(
|
body: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
Stack(children: [
|
||||||
padding: const EdgeInsets.only(bottom: 16),
|
ClipRRect(
|
||||||
child: Image.network(
|
child: Image.network(
|
||||||
data.imgUrl ?? '',
|
data.img ?? '',
|
||||||
|
errorBuilder: (_, __, ___) => const Placeholder(),
|
||||||
|
height: 370,
|
||||||
|
alignment: Alignment.topCenter,
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
width: double.infinity,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 4, top: 16, right: 20, left: 20),
|
||||||
|
child: Text(
|
||||||
|
data.name,
|
||||||
|
style: const TextStyle(
|
||||||
|
color: Colors.white70,
|
||||||
|
fontSize: 30,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
Padding(
|
||||||
Padding(
|
padding: const EdgeInsets.only(bottom: 4, top: 16, right: 20, left: 20),
|
||||||
padding: const EdgeInsets.only(bottom: 4),
|
|
||||||
child: Text(
|
child: Text(
|
||||||
data.text,
|
data.description,
|
||||||
style: Theme.of(context).textTheme.headlineLarge,
|
style: const TextStyle(
|
||||||
|
color: Colors.white70,
|
||||||
|
fontSize: 20,
|
||||||
|
fontWeight: FontWeight.normal,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
Text(
|
|
||||||
data.description,
|
|
||||||
style: Theme.of(context).textTheme.bodyLarge,
|
|
||||||
)
|
)
|
||||||
],
|
])
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,37 +1,29 @@
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:pmd_lab/presentation/home_page/bloc/events.dart';
|
import 'package:pmd_lab/presentation/home_page/bloc/events.dart';
|
||||||
import 'package:pmd_lab/presentation/home_page/bloc/state.dart';
|
import 'package:pmd_lab/presentation/home_page/bloc/state.dart';
|
||||||
import 'package:pmd_lab/repositories/potter_repository.dart';
|
import 'package:pmd_lab/repositories/api_interface.dart';
|
||||||
|
import 'package:pmd_lab/repositories/mock_repository.dart';
|
||||||
|
import 'package:pmd_lab/repositories/titans_repository.dart';
|
||||||
|
|
||||||
class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
||||||
final PotterRepository repo;
|
final TitansRepository repo;
|
||||||
|
|
||||||
HomeBloc(this.repo) : super(const HomeState()) {
|
HomeBloc(this.repo) : super(const HomeState()) {
|
||||||
on<HomeLoadDataEvent>(_onLoadData);
|
on<HomeLoadDataEvent>(_onLoadData);
|
||||||
}
|
}
|
||||||
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
String? error;
|
String? error;
|
||||||
|
|
||||||
final data = await repo.loadData(
|
final data = await repo.loadResults(
|
||||||
q: event.search,
|
q: event.search,
|
||||||
page: event.nextPage ?? 1,
|
|
||||||
onError: (e) => error = e,
|
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,
|
error: error,
|
||||||
));
|
));
|
||||||
|
@ -1,33 +1,29 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:copy_with_extension/copy_with_extension.dart';
|
import 'package:copy_with_extension/copy_with_extension.dart';
|
||||||
import 'package:pmd_lab/domain/models/home.dart';
|
import 'package:pmd_lab/domain/models/card.dart';
|
||||||
|
|
||||||
part 'state.g.dart';
|
part 'state.g.dart';
|
||||||
|
|
||||||
@CopyWith()
|
@CopyWith()
|
||||||
class HomeState extends Equatable {
|
class HomeState extends Equatable {
|
||||||
final HomeData? data;
|
final List<CardData>? data;
|
||||||
final bool isLoading;
|
final bool isLoading;
|
||||||
final bool isPaginationLoading;
|
|
||||||
final String? error;
|
final String? error;
|
||||||
|
|
||||||
const HomeState({
|
const HomeState({
|
||||||
this.data,
|
this.data,
|
||||||
this.isLoading = false,
|
this.isLoading = false,
|
||||||
this.isPaginationLoading = false,
|
|
||||||
this.error,
|
this.error,
|
||||||
});
|
});
|
||||||
|
|
||||||
HomeState copyWith({
|
HomeState copyWith({
|
||||||
HomeData? data,
|
List<CardData>? data,
|
||||||
bool? isLoading,
|
bool? isLoading,
|
||||||
bool? isPaginationLoading,
|
|
||||||
String? error,
|
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,
|
error: error ?? this.error,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -35,7 +31,6 @@ class HomeState extends Equatable {
|
|||||||
List<Object?> get props => [
|
List<Object?> get props => [
|
||||||
data,
|
data,
|
||||||
isLoading,
|
isLoading,
|
||||||
isPaginationLoading,
|
|
||||||
error,
|
error,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -7,12 +7,10 @@ part of 'state.dart';
|
|||||||
// **************************************************************************
|
// **************************************************************************
|
||||||
|
|
||||||
abstract class _$HomeStateCWProxy {
|
abstract class _$HomeStateCWProxy {
|
||||||
HomeState data(HomeData? data);
|
HomeState data(List<CardData>? data);
|
||||||
|
|
||||||
HomeState isLoading(bool isLoading);
|
HomeState isLoading(bool isLoading);
|
||||||
|
|
||||||
HomeState isPaginationLoading(bool isPaginationLoading);
|
|
||||||
|
|
||||||
HomeState error(String? error);
|
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.
|
/// 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.
|
||||||
@ -22,9 +20,8 @@ abstract class _$HomeStateCWProxy {
|
|||||||
/// HomeState(...).copyWith(id: 12, name: "My name")
|
/// HomeState(...).copyWith(id: 12, name: "My name")
|
||||||
/// ````
|
/// ````
|
||||||
HomeState call({
|
HomeState call({
|
||||||
HomeData? data,
|
List<CardData>? data,
|
||||||
bool? isLoading,
|
bool? isLoading,
|
||||||
bool? isPaginationLoading,
|
|
||||||
String? error,
|
String? error,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -36,15 +33,11 @@ class _$HomeStateCWProxyImpl implements _$HomeStateCWProxy {
|
|||||||
final HomeState _value;
|
final HomeState _value;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
HomeState data(HomeData? data) => this(data: data);
|
HomeState data(List<CardData>? data) => this(data: data);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
HomeState isLoading(bool isLoading) => this(isLoading: isLoading);
|
HomeState isLoading(bool isLoading) => this(isLoading: isLoading);
|
||||||
|
|
||||||
@override
|
|
||||||
HomeState isPaginationLoading(bool isPaginationLoading) =>
|
|
||||||
this(isPaginationLoading: isPaginationLoading);
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
HomeState error(String? error) => this(error: error);
|
HomeState error(String? error) => this(error: error);
|
||||||
|
|
||||||
@ -59,24 +52,17 @@ class _$HomeStateCWProxyImpl implements _$HomeStateCWProxy {
|
|||||||
HomeState call({
|
HomeState call({
|
||||||
Object? data = const $CopyWithPlaceholder(),
|
Object? data = const $CopyWithPlaceholder(),
|
||||||
Object? isLoading = const $CopyWithPlaceholder(),
|
Object? isLoading = const $CopyWithPlaceholder(),
|
||||||
Object? isPaginationLoading = const $CopyWithPlaceholder(),
|
|
||||||
Object? error = const $CopyWithPlaceholder(),
|
Object? error = const $CopyWithPlaceholder(),
|
||||||
}) {
|
}) {
|
||||||
return HomeState(
|
return HomeState(
|
||||||
data: data == const $CopyWithPlaceholder()
|
data: data == const $CopyWithPlaceholder()
|
||||||
? _value.data
|
? _value.data
|
||||||
// ignore: cast_nullable_to_non_nullable
|
// ignore: cast_nullable_to_non_nullable
|
||||||
: data as HomeData?,
|
: data as List<CardData>?,
|
||||||
isLoading: isLoading == const $CopyWithPlaceholder() || isLoading == null
|
isLoading: isLoading == const $CopyWithPlaceholder() || isLoading == null
|
||||||
? _value.isLoading
|
? _value.isLoading
|
||||||
// ignore: cast_nullable_to_non_nullable
|
// ignore: cast_nullable_to_non_nullable
|
||||||
: isLoading as bool,
|
: isLoading as bool,
|
||||||
isPaginationLoading:
|
|
||||||
isPaginationLoading == const $CopyWithPlaceholder() ||
|
|
||||||
isPaginationLoading == null
|
|
||||||
? _value.isPaginationLoading
|
|
||||||
// ignore: cast_nullable_to_non_nullable
|
|
||||||
: isPaginationLoading as bool,
|
|
||||||
error: error == const $CopyWithPlaceholder()
|
error: error == const $CopyWithPlaceholder()
|
||||||
? _value.error
|
? _value.error
|
||||||
// ignore: cast_nullable_to_non_nullable
|
// ignore: cast_nullable_to_non_nullable
|
||||||
|
@ -28,9 +28,9 @@ class _Card extends StatelessWidget {
|
|||||||
bool isLiked = false,
|
bool isLiked = false,
|
||||||
}) =>
|
}) =>
|
||||||
_Card(
|
_Card(
|
||||||
data.text,
|
data.name,
|
||||||
description: data.description,
|
description: data.description,
|
||||||
imgUrl: data.imgUrl,
|
imgUrl: data.img,
|
||||||
onLike: onLike,
|
onLike: onLike,
|
||||||
onTap: onTap,
|
onTap: onTap,
|
||||||
isLiked: isLiked,
|
isLiked: isLiked,
|
||||||
@ -44,14 +44,12 @@ class _Card extends StatelessWidget {
|
|||||||
child: Container(
|
child: Container(
|
||||||
margin: const EdgeInsets.only(bottom: 20),
|
margin: const EdgeInsets.only(bottom: 20),
|
||||||
decoration:
|
decoration:
|
||||||
BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(20), boxShadow: [
|
BoxDecoration(color: Color(0xFF272727), borderRadius: BorderRadius.circular(20),
|
||||||
BoxShadow(
|
border: Border.all( // Задаем рамку
|
||||||
color: Colors.black.withOpacity(0.1),
|
color: Colors.white12, // Цвет рамки
|
||||||
spreadRadius: 1,
|
width: 2, // Толщина рамки
|
||||||
offset: const Offset(0, 0),
|
),
|
||||||
blurRadius: 15,
|
),
|
||||||
)
|
|
||||||
]),
|
|
||||||
child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
|
child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
|
||||||
Stack(children: [
|
Stack(children: [
|
||||||
ClipRRect(
|
ClipRRect(
|
||||||
@ -77,7 +75,7 @@ class _Card extends StatelessWidget {
|
|||||||
child: Text(
|
child: Text(
|
||||||
text,
|
text,
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
color: Color(0xff4c4c4c),
|
color: Colors.white70,
|
||||||
fontSize: 30,
|
fontSize: 30,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
@ -86,7 +84,7 @@ class _Card extends StatelessWidget {
|
|||||||
Text(
|
Text(
|
||||||
description,
|
description,
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
color: Color(0xff9c9c9c),
|
color: Colors.white70,
|
||||||
fontSize: 20,
|
fontSize: 20,
|
||||||
fontWeight: FontWeight.normal,
|
fontWeight: FontWeight.normal,
|
||||||
),
|
),
|
||||||
@ -105,6 +103,7 @@ class _Card extends StatelessWidget {
|
|||||||
)
|
)
|
||||||
: const Icon(
|
: const Icon(
|
||||||
Icons.favorite_border,
|
Icons.favorite_border,
|
||||||
|
color: Colors.white,
|
||||||
key: ValueKey<int>(1),
|
key: ValueKey<int>(1),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -14,9 +14,7 @@ import 'package:pmd_lab/presentation/like_bloc/like_event.dart';
|
|||||||
import 'package:pmd_lab/presentation/like_bloc/like_state.dart';
|
import 'package:pmd_lab/presentation/like_bloc/like_state.dart';
|
||||||
import 'package:pmd_lab/presentation/locale_bloc/locale_events.dart';
|
import 'package:pmd_lab/presentation/locale_bloc/locale_events.dart';
|
||||||
import 'package:pmd_lab/presentation/locale_bloc/locale_state.dart';
|
import 'package:pmd_lab/presentation/locale_bloc/locale_state.dart';
|
||||||
import 'package:pmd_lab/repositories/api_interface.dart';
|
import 'package:pmd_lab/repositories/titans_repository.dart';
|
||||||
import 'package:pmd_lab/repositories/potter_repository.dart';
|
|
||||||
|
|
||||||
import '../locale_bloc/locale_bloc.dart';
|
import '../locale_bloc/locale_bloc.dart';
|
||||||
part 'card.dart';
|
part 'card.dart';
|
||||||
|
|
||||||
@ -41,37 +39,20 @@ class Body extends StatefulWidget {
|
|||||||
|
|
||||||
class _BodyState extends State<Body> {
|
class _BodyState extends State<Body> {
|
||||||
final searchController = TextEditingController();
|
final searchController = TextEditingController();
|
||||||
final scrollController = ScrollController();
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
SvgObjects.init();
|
SvgObjects.init();
|
||||||
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
context.read<HomeBloc>().add(const HomeLoadDataEvent());
|
context.read<HomeBloc>().add(const HomeLoadDataEvent());
|
||||||
context.read<LikeBloc>().add(const LoadLikesEvent());
|
context.read<LikeBloc>().add(const LoadLikesEvent());
|
||||||
});
|
});
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,6 +71,13 @@ class _BodyState extends State<Body> {
|
|||||||
child: CupertinoSearchTextField(
|
child: CupertinoSearchTextField(
|
||||||
controller: searchController,
|
controller: searchController,
|
||||||
placeholder: context.locale.search,
|
placeholder: context.locale.search,
|
||||||
|
backgroundColor: Colors.white12,
|
||||||
|
placeholderStyle: TextStyle(
|
||||||
|
color: Colors.white, // Задайте желаемый цвет плейсхолдера// (Необязательно) Задайте размер шрифта(Необязательно) Задайте стиль шрифта
|
||||||
|
),
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
onChanged: (search) {
|
onChanged: (search) {
|
||||||
Debounce.run(() => context.read<HomeBloc>().add(HomeLoadDataEvent(search: search)));
|
Debounce.run(() => context.read<HomeBloc>().add(HomeLoadDataEvent(search: search)));
|
||||||
},
|
},
|
||||||
@ -130,11 +118,10 @@ class _BodyState extends State<Body> {
|
|||||||
onRefresh: _onRefresh,
|
onRefresh: _onRefresh,
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
physics: const BouncingScrollPhysics(),
|
physics: const BouncingScrollPhysics(),
|
||||||
controller: scrollController,
|
padding: const EdgeInsets.all(12),
|
||||||
padding: EdgeInsets.zero,
|
itemCount: state.data?.length ?? 0,
|
||||||
itemCount: state.data?.data?.length ?? 0,
|
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final data = state.data?.data?[index];
|
final data = state.data?[index];
|
||||||
return data != null
|
return data != null
|
||||||
? _Card.fromData(
|
? _Card.fromData(
|
||||||
data,
|
data,
|
||||||
@ -150,12 +137,7 @@ class _BodyState extends State<Body> {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
), // Expanded
|
), // Expanded
|
||||||
), // BlocBuilder
|
) // BlocBuilder
|
||||||
BlocBuilder<HomeBloc, HomeState>(
|
|
||||||
builder: (context, state) => state.isPaginationLoading
|
|
||||||
? const CircularProgressIndicator()
|
|
||||||
: const SizedBox.shrink(),
|
|
||||||
)
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -168,7 +150,7 @@ class _BodyState extends State<Body> {
|
|||||||
'$title ${isLiked ? context.locale.liked : context.locale.disliked}',
|
'$title ${isLiked ? context.locale.liked : context.locale.disliked}',
|
||||||
style: Theme.of(context).textTheme.bodyLarge,
|
style: Theme.of(context).textTheme.bodyLarge,
|
||||||
),
|
),
|
||||||
backgroundColor: Colors.orangeAccent,
|
backgroundColor: Colors.white,
|
||||||
duration: const Duration(seconds: 1),
|
duration: const Duration(seconds: 1),
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
@ -188,7 +170,7 @@ class _BodyState extends State<Body> {
|
|||||||
|
|
||||||
void _onLike(String? id, String title, bool isLiked) {
|
void _onLike(String? id, String title, bool isLiked) {
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
context.read<LikeBloc>().add(ChangeLikeEvent(id));
|
context.read<LikeBloc>().add(ChangeLikeEvent(id.toString()));
|
||||||
_showSnackBar(context, title, !isLiked);
|
_showSnackBar(context, title, !isLiked);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import 'package:pmd_lab/domain/models/home.dart';
|
import 'package:pmd_lab/domain/models/card.dart';
|
||||||
|
|
||||||
typedef OnErrorCallback = void Function(String? error);
|
typedef OnErrorCallback = void Function(String? error);
|
||||||
|
|
||||||
abstract class ApiInterface {
|
abstract class ApiInterface {
|
||||||
Future<HomeData?> loadData({OnErrorCallback? onError});
|
Future<List<CardData>?> loadResults({OnErrorCallback? onError});
|
||||||
}
|
}
|
||||||
|
@ -1,29 +1,28 @@
|
|||||||
import 'package:pmd_lab/domain/models/home.dart';
|
import 'package:pmd_lab/domain/models/card.dart';
|
||||||
import 'package:pmd_lab/repositories/api_interface.dart';
|
import 'package:pmd_lab/repositories/api_interface.dart';
|
||||||
|
|
||||||
class MockRepository extends ApiInterface {
|
class MockRepository extends ApiInterface {
|
||||||
@override
|
@override
|
||||||
Future<HomeData?> loadData({OnErrorCallback? onError}) async {
|
Future<List<CardData>?> loadResults({OnErrorCallback? onError, String? q}) async {
|
||||||
return HomeData();
|
return [
|
||||||
// return [
|
CardData(
|
||||||
// CardData(
|
'Freeze',
|
||||||
// 'Какая-то новость',
|
description: 'so cold..',
|
||||||
// description: 'В данном блоке рекомендуем разместить краткую информацию',
|
img:
|
||||||
// imgUrl:
|
'https://www.skedaddlewildlife.com/wp-content/uploads/2018/09/depositphotos_22425309-stock-photo-a-lonely-raccoon-in-winter.jpg',
|
||||||
// 'https://universal.revengel.ru/assets/cache_image/images/services/3_731x487_1cb.png',
|
),
|
||||||
// ),
|
CardData(
|
||||||
// CardData(
|
'Hi',
|
||||||
// 'Ещё какая-то новость',
|
description: 'pretty face',
|
||||||
// description: 'В данном блоке рекомендуем разместить краткую информацию',
|
img:
|
||||||
// imgUrl:
|
'https://www.thesprucepets.com/thmb/nKNaS4I586B_H7sEUw9QAXvWM_0=/2121x0/filters:no_upscale():strip_icc()/GettyImages-135630198-5ba7d225c9e77c0050cff91b.jpg',
|
||||||
// "https://universal.revengel.ru/assets/cache_image/images/services/2_731x487_1cb.png",
|
),
|
||||||
// ),
|
CardData(
|
||||||
// CardData(
|
'Orange',
|
||||||
// 'Ещё одна новость',
|
description: 'I like autumn',
|
||||||
// description: 'В данном блоке рекомендуем разместить краткую информацию',
|
img: 'https://furmanagers.com/wp-content/uploads/2019/11/dreamstime_l_22075357.jpg',
|
||||||
// imgUrl:
|
),
|
||||||
// "https://universal.revengel.ru/assets/cache_image/images/services/1_731x487_1cb.png",
|
];
|
||||||
// )
|
|
||||||
//];
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
}
|
@ -1,44 +0,0 @@
|
|||||||
import 'package:dio/dio.dart';
|
|
||||||
import 'package:pmd_lab/data/dtos/characters_dto.dart';
|
|
||||||
import 'package:pmd_lab/data/mappes/characters_mapper.dart';
|
|
||||||
import 'package:pmd_lab/domain/models/home.dart';
|
|
||||||
import 'package:pmd_lab/repositories/api_interface.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 = 25,
|
|
||||||
}) 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
38
lib/repositories/titans_repository.dart
Normal file
38
lib/repositories/titans_repository.dart
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:pmd_lab/data/dtos/titans_dto.dart';
|
||||||
|
import 'package:pmd_lab/data/mappes/titans_mapper.dart';
|
||||||
|
import 'package:pmd_lab/domain/models/card.dart';
|
||||||
|
import 'package:pmd_lab/repositories/api_interface.dart';
|
||||||
|
import 'package:pretty_dio_logger/pretty_dio_logger.dart';
|
||||||
|
|
||||||
|
class TitansRepository extends ApiInterface {
|
||||||
|
static final Dio _dio = Dio()
|
||||||
|
..interceptors.add(PrettyDioLogger(
|
||||||
|
requestHeader: true,
|
||||||
|
requestBody: true,
|
||||||
|
));
|
||||||
|
|
||||||
|
static const String _baseUrl = 'https://api.attackontitanapi.com';
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<List<CardData>?> loadResults({
|
||||||
|
OnErrorCallback? onError,
|
||||||
|
String? q
|
||||||
|
}) async {
|
||||||
|
try {
|
||||||
|
const String url = '$_baseUrl/titans';
|
||||||
|
|
||||||
|
final Response<dynamic> response = await _dio.get<Map<dynamic, dynamic>>(
|
||||||
|
url,
|
||||||
|
queryParameters: q != null ? {'name': q} : null,
|
||||||
|
);
|
||||||
|
|
||||||
|
final TitansDto dto = TitansDto.fromJson(response.data as Map<String, dynamic>);
|
||||||
|
final List<CardData>? results = dto.results?.map((e) => e.toDomain()).toList();
|
||||||
|
return results;
|
||||||
|
} on DioException catch (e) {
|
||||||
|
onError?.call(e.error?.toString());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user