курсовая
This commit is contained in:
parent
9e76b66976
commit
6f3aee08f1
BIN
assets/fruits.jpg
Normal file
BIN
assets/fruits.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 118 KiB |
@ -13,7 +13,7 @@ class SearchController with ChangeNotifier {
|
|||||||
if (_query != null && _query!.isNotEmpty) {
|
if (_query != null && _query!.isNotEmpty) {
|
||||||
try {
|
try {
|
||||||
final Response<dynamic> response = await _dio.get<Map<dynamic, dynamic>>(
|
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},
|
queryParameters: {'filter[name_const]': _query},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -24,15 +24,14 @@ class WordDataDto {
|
|||||||
|
|
||||||
@JsonSerializable(createToJson: false)
|
@JsonSerializable(createToJson: false)
|
||||||
class WordAttributesDataDto {
|
class WordAttributesDataDto {
|
||||||
final String? name;
|
final String? word;
|
||||||
final String? born;
|
final String? translation;
|
||||||
final String? died;
|
|
||||||
final String? image;
|
final String? image;
|
||||||
|
|
||||||
factory WordAttributesDataDto.fromJson(Map<String, dynamic> json) =>
|
factory WordAttributesDataDto.fromJson(Map<String, dynamic> json) =>
|
||||||
_$WordAttributesDataDtoFromJson(json);
|
_$WordAttributesDataDtoFromJson(json);
|
||||||
|
|
||||||
WordAttributesDataDto(this.name, this.born, this.died, this.image);
|
WordAttributesDataDto(this.word, this.translation, this.image);
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonSerializable(createToJson: false)
|
@JsonSerializable(createToJson: false)
|
||||||
|
@ -27,9 +27,8 @@ WordDataDto _$WordDataDtoFromJson(Map<String, dynamic> json) => WordDataDto(
|
|||||||
WordAttributesDataDto _$WordAttributesDataDtoFromJson(
|
WordAttributesDataDto _$WordAttributesDataDtoFromJson(
|
||||||
Map<String, dynamic> json) =>
|
Map<String, dynamic> json) =>
|
||||||
WordAttributesDataDto(
|
WordAttributesDataDto(
|
||||||
json['name'] as String?,
|
json['word'] as String?,
|
||||||
json['born'] as String?,
|
json['translation'] as String?,
|
||||||
json['died'] as String?,
|
|
||||||
json['image'] as String?,
|
json['image'] as String?,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -3,13 +3,13 @@ import 'package:card_app/domain/models/card.dart';
|
|||||||
import 'package:card_app/domain/models/home.dart';
|
import 'package:card_app/domain/models/home.dart';
|
||||||
|
|
||||||
const _imagePlaceholder =
|
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 {
|
extension WordDataDtoToModel on WordDataDto {
|
||||||
CardData toDomain() => CardData(
|
CardData toDomain() => CardData(
|
||||||
word: attributes?.name ?? 'UNKNOWN',
|
word: attributes?.word ?? 'UNKNOWN',
|
||||||
image: attributes?.image ?? _imagePlaceholder,
|
image: attributes?.image ?? _imagePlaceholder,
|
||||||
translation: '${attributes?.born}',
|
translation: '${attributes?.translation}',
|
||||||
id: id,
|
id: id,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,12 @@ class CardData {
|
|||||||
final String word;
|
final String word;
|
||||||
final String translation;
|
final String translation;
|
||||||
final String? image;
|
final String? image;
|
||||||
final int mark;
|
|
||||||
final String? id;
|
final String? id;
|
||||||
|
|
||||||
const CardData({
|
const CardData({
|
||||||
required this.word,
|
required this.word,
|
||||||
required this.translation,
|
required this.translation,
|
||||||
required this.image,
|
required this.image,
|
||||||
this.mark = 0,
|
|
||||||
this.id
|
this.id
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -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/events.dart';
|
||||||
import 'package:card_app/presentation/home_page/bloc/state.dart';
|
import 'package:card_app/presentation/home_page/bloc/state.dart';
|
||||||
import 'package:card_app/repositories/WordsRepository.dart';
|
import 'package:card_app/repositories/WordsRepository.dart';
|
||||||
@ -19,6 +20,7 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String? error;
|
String? error;
|
||||||
|
|
||||||
final data =
|
final data =
|
||||||
await repo.loadData(q: event.search, page: event.nextPage ?? 1, onError: (e) => error = e);
|
await repo.loadData(q: event.search, page: event.nextPage ?? 1, onError: (e) => error = e);
|
||||||
|
|
||||||
|
@ -36,7 +36,6 @@ class _Card extends StatelessWidget {
|
|||||||
word: data.word,
|
word: data.word,
|
||||||
translation: data.translation,
|
translation: data.translation,
|
||||||
image: data.image ?? "",
|
image: data.image ?? "",
|
||||||
mark: data.mark,
|
|
||||||
onKnow: onKnow,
|
onKnow: onKnow,
|
||||||
onTap: onTap,
|
onTap: onTap,
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ class WordsRepository extends ApiInterface {
|
|||||||
requestBody: true,
|
requestBody: true,
|
||||||
));
|
));
|
||||||
|
|
||||||
static const String _baseUrl = 'https://api.potterdb.com';
|
static const String _baseUrl = 'http://10.0.2.2:5000/flashcards';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<HomeData?> loadData({
|
Future<HomeData?> loadData({
|
||||||
@ -24,7 +24,7 @@ class WordsRepository extends ApiInterface {
|
|||||||
int pageSize = 5,
|
int pageSize = 5,
|
||||||
}) async {
|
}) async {
|
||||||
try {
|
try {
|
||||||
const String url = '$_baseUrl/v1/characters';
|
const String url = _baseUrl;
|
||||||
|
|
||||||
final Response<dynamic> response = await _dio.get<Map<dynamic, dynamic>>(
|
final Response<dynamic> response = await _dio.get<Map<dynamic, dynamic>>(
|
||||||
url,
|
url,
|
||||||
|
@ -12,14 +12,14 @@ class MockRepository extends ApiInterface {
|
|||||||
translation: 'Привет',
|
translation: 'Привет',
|
||||||
image:
|
image:
|
||||||
'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS69a8OWnRueQNykBpuyfbGxl3gt5ct46NOHg&s',
|
'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS69a8OWnRueQNykBpuyfbGxl3gt5ct46NOHg&s',
|
||||||
mark: 10,
|
|
||||||
),
|
),
|
||||||
CardData(
|
CardData(
|
||||||
word: 'Book',
|
word: 'Book',
|
||||||
translation: 'Книга',
|
translation: 'Книга',
|
||||||
image:
|
image:
|
||||||
'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSfbH7Ckkbzrr3KZlb144GTaAmJnz87U9opGw&s',
|
'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSfbH7Ckkbzrr3KZlb144GTaAmJnz87U9opGw&s',
|
||||||
mark: 0),
|
),
|
||||||
CardData(
|
CardData(
|
||||||
word: 'Cat',
|
word: 'Cat',
|
||||||
translation: 'Кот',
|
translation: 'Кот',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user