курсовая

This commit is contained in:
ValAn 2024-12-21 15:24:04 +04:00
parent 9e76b66976
commit 6f3aee08f1
10 changed files with 15 additions and 18 deletions

BIN
assets/fruits.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 KiB

View File

@ -13,7 +13,7 @@ class SearchController with ChangeNotifier {
if (_query != null && _query!.isNotEmpty) {
try {
final Response<dynamic> response = await _dio.get<Map<dynamic, dynamic>>(
'https://api.potterdb.com/v1/characters',
'http://10.0.2.2:5000/flashcards',
queryParameters: {'filter[name_const]': _query},
);

View File

@ -24,15 +24,14 @@ class WordDataDto {
@JsonSerializable(createToJson: false)
class WordAttributesDataDto {
final String? name;
final String? born;
final String? died;
final String? word;
final String? translation;
final String? image;
factory WordAttributesDataDto.fromJson(Map<String, dynamic> json) =>
_$WordAttributesDataDtoFromJson(json);
WordAttributesDataDto(this.name, this.born, this.died, this.image);
WordAttributesDataDto(this.word, this.translation, this.image);
}
@JsonSerializable(createToJson: false)

View File

@ -27,9 +27,8 @@ WordDataDto _$WordDataDtoFromJson(Map<String, dynamic> json) => WordDataDto(
WordAttributesDataDto _$WordAttributesDataDtoFromJson(
Map<String, dynamic> json) =>
WordAttributesDataDto(
json['name'] as String?,
json['born'] as String?,
json['died'] as String?,
json['word'] as String?,
json['translation'] as String?,
json['image'] as String?,
);

View File

@ -3,13 +3,13 @@ import 'package:card_app/domain/models/card.dart';
import 'package:card_app/domain/models/home.dart';
const _imagePlaceholder =
'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS69a8OWnRueQNykBpuyfbGxl3gt5ct46NOHg&s';
'https://yesfrukt.com/storage/source/f96cd9ce000c140442ae0b067aa84978/content/1/5rKj4rEukLwUqOZCW_DG3RZ2NO14IZ7s.jpg';
extension WordDataDtoToModel on WordDataDto {
CardData toDomain() => CardData(
word: attributes?.name ?? 'UNKNOWN',
word: attributes?.word ?? 'UNKNOWN',
image: attributes?.image ?? _imagePlaceholder,
translation: '${attributes?.born}',
translation: '${attributes?.translation}',
id: id,
);
}

View File

@ -2,14 +2,12 @@ class CardData {
final String word;
final String translation;
final String? image;
final int mark;
final String? id;
const CardData({
required this.word,
required this.translation,
required this.image,
this.mark = 0,
this.id
});
}

View File

@ -1,3 +1,4 @@
import 'package:card_app/domain/models/home.dart';
import 'package:card_app/presentation/home_page/bloc/events.dart';
import 'package:card_app/presentation/home_page/bloc/state.dart';
import 'package:card_app/repositories/WordsRepository.dart';
@ -19,6 +20,7 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
}
String? error;
final data =
await repo.loadData(q: event.search, page: event.nextPage ?? 1, onError: (e) => error = e);

View File

@ -36,7 +36,6 @@ class _Card extends StatelessWidget {
word: data.word,
translation: data.translation,
image: data.image ?? "",
mark: data.mark,
onKnow: onKnow,
onTap: onTap,

View File

@ -14,7 +14,7 @@ class WordsRepository extends ApiInterface {
requestBody: true,
));
static const String _baseUrl = 'https://api.potterdb.com';
static const String _baseUrl = 'http://10.0.2.2:5000/flashcards';
@override
Future<HomeData?> loadData({
@ -24,7 +24,7 @@ class WordsRepository extends ApiInterface {
int pageSize = 5,
}) async {
try {
const String url = '$_baseUrl/v1/characters';
const String url = _baseUrl;
final Response<dynamic> response = await _dio.get<Map<dynamic, dynamic>>(
url,

View File

@ -12,14 +12,14 @@ class MockRepository extends ApiInterface {
translation: 'Привет',
image:
'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS69a8OWnRueQNykBpuyfbGxl3gt5ct46NOHg&s',
mark: 10,
),
CardData(
word: 'Book',
translation: 'Книга',
image:
'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSfbH7Ckkbzrr3KZlb144GTaAmJnz87U9opGw&s',
mark: 0),
),
CardData(
word: 'Cat',
translation: 'Кот',