Готовая 5 лаба
This commit is contained in:
parent
19f937922f
commit
8083c2367f
@ -12,9 +12,17 @@ extension UserDtoToModel on UserDto {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return CardPostData(
|
return CardPostData(
|
||||||
name ?? "",
|
name: name ?? "",
|
||||||
description ?? "",
|
surname: surname ?? "",
|
||||||
isValidImageUrl(image) ? image! : "https://placehold.co/480x640/png",
|
description: description ?? "",
|
||||||
false);
|
imageUrl: isValidImageUrl(image)
|
||||||
|
? image
|
||||||
|
: (gender! == "male"
|
||||||
|
? "https://avatar.iran.liara.run/public/boy"
|
||||||
|
: "https://avatar.iran.liara.run/public/girl")
|
||||||
|
.toString(),
|
||||||
|
isLiked: false,
|
||||||
|
age: age,
|
||||||
|
distance: distance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
30
lib/data/repositories/api_user_repository.dart
Normal file
30
lib/data/repositories/api_user_repository.dart
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import 'package:pmu/data/dto/page_dto.dart';
|
||||||
|
import 'package:pmu/data/dto/user_dto.dart';
|
||||||
|
import 'package:pmu/data/mappers/user_mapper.dart';
|
||||||
|
import 'package:pmu/data/repositories/api_interface.dart';
|
||||||
|
import 'package:pmu/domain/card.dart';
|
||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:pretty_dio_logger/pretty_dio_logger.dart';
|
||||||
|
|
||||||
|
class ApiUserRepository extends ApiInterface {
|
||||||
|
static final Dio _dio = Dio()
|
||||||
|
..interceptors.add(PrettyDioLogger(requestHeader: true, requestBody: true));
|
||||||
|
static const String _baseUrl =
|
||||||
|
'http://lovesearch-api.nspotapov.ru/api/users/';
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<List<CardPostData>?> loadData() async {
|
||||||
|
const String url = _baseUrl;
|
||||||
|
final List<CardPostData> data = [];
|
||||||
|
final Response<dynamic> response =
|
||||||
|
await _dio.get<Map<dynamic, dynamic>>(url);
|
||||||
|
final PageDto pageDto =
|
||||||
|
PageDto.fromJson(response.data as Map<String, dynamic>);
|
||||||
|
int itemsCount = pageDto.itemsCount ?? 0;
|
||||||
|
for (int i = 0; i < itemsCount; i++) {
|
||||||
|
final CardPostData cardPost = pageDto.items![i].toDomain();
|
||||||
|
data.add(cardPost);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
@ -5,70 +5,6 @@ class MockUserRepository extends ApiInterface {
|
|||||||
@override
|
@override
|
||||||
Future<List<CardPostData>?> loadData() async {
|
Future<List<CardPostData>?> loadData() async {
|
||||||
return [
|
return [
|
||||||
const CardPostData(
|
|
||||||
name: "Марьяна",
|
|
||||||
surname: "Ро",
|
|
||||||
description: "Люблю вечерами погамать в майн",
|
|
||||||
imageUrl: "https://placehold.co/600x400/png",
|
|
||||||
age: 21,
|
|
||||||
distance: 24.5,
|
|
||||||
isLiked: false),
|
|
||||||
const CardPostData(
|
|
||||||
name: "Константин",
|
|
||||||
surname: "Злобин",
|
|
||||||
description: "Веду канал в тг про криптожизнь",
|
|
||||||
imageUrl: "https://placehold.co/600x400/png",
|
|
||||||
age: 24,
|
|
||||||
distance: 478.3,
|
|
||||||
isLiked: false),
|
|
||||||
const CardPostData(
|
|
||||||
name: "Марьяна",
|
|
||||||
surname: "Ро",
|
|
||||||
description: "Люблю вечерами погамать в майн",
|
|
||||||
imageUrl: "https://placehold.co/600x400/png",
|
|
||||||
age: 21,
|
|
||||||
distance: 24.5,
|
|
||||||
isLiked: false),
|
|
||||||
const CardPostData(
|
|
||||||
name: "Константин",
|
|
||||||
surname: "Злобин",
|
|
||||||
description: "Веду канал в тг про криптожизнь",
|
|
||||||
imageUrl: "https://placehold.co/600x400/png",
|
|
||||||
age: 24,
|
|
||||||
distance: 478.3,
|
|
||||||
isLiked: false),
|
|
||||||
const CardPostData(
|
|
||||||
name: "Марьяна",
|
|
||||||
surname: "Ро",
|
|
||||||
description: "Люблю вечерами погамать в майн",
|
|
||||||
imageUrl: "https://placehold.co/600x400/png",
|
|
||||||
age: 21,
|
|
||||||
distance: 24.5,
|
|
||||||
isLiked: false),
|
|
||||||
const CardPostData(
|
|
||||||
name: "Константин",
|
|
||||||
surname: "Злобин",
|
|
||||||
description: "Веду канал в тг про криптожизнь",
|
|
||||||
imageUrl: "https://placehold.co/600x400/png",
|
|
||||||
age: 24,
|
|
||||||
distance: 478.3,
|
|
||||||
isLiked: false),
|
|
||||||
const CardPostData(
|
|
||||||
name: "Марьяна",
|
|
||||||
surname: "Ро",
|
|
||||||
description: "Люблю вечерами погамать в майн",
|
|
||||||
imageUrl: "https://placehold.co/600x400/png",
|
|
||||||
age: 21,
|
|
||||||
distance: 24.5,
|
|
||||||
isLiked: false),
|
|
||||||
const CardPostData(
|
|
||||||
name: "Константин",
|
|
||||||
surname: "Злобин",
|
|
||||||
description: "Веду канал в тг про криптожизнь",
|
|
||||||
imageUrl: "https://placehold.co/600x400/png",
|
|
||||||
age: 24,
|
|
||||||
distance: 478.3,
|
|
||||||
isLiked: false),
|
|
||||||
const CardPostData(
|
const CardPostData(
|
||||||
name: "Марьяна",
|
name: "Марьяна",
|
||||||
surname: "Ро",
|
surname: "Ро",
|
||||||
|
@ -1,8 +1,18 @@
|
|||||||
class CardPostData {
|
class CardPostData {
|
||||||
final String name;
|
final String? name;
|
||||||
final String description;
|
final String? surname;
|
||||||
|
final String? description;
|
||||||
final String? imageUrl;
|
final String? imageUrl;
|
||||||
final bool isLiked;
|
final int? age;
|
||||||
|
final double? distance;
|
||||||
|
final bool? isLiked;
|
||||||
|
|
||||||
const CardPostData(this.name, this.description, this.imageUrl, this.isLiked);
|
const CardPostData(
|
||||||
|
{this.name,
|
||||||
|
this.surname,
|
||||||
|
this.description,
|
||||||
|
this.imageUrl,
|
||||||
|
this.isLiked,
|
||||||
|
this.age,
|
||||||
|
this.distance});
|
||||||
}
|
}
|
||||||
|
@ -25,14 +25,14 @@ class DetailPage extends StatelessWidget {
|
|||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(4.0),
|
padding: const EdgeInsets.all(4.0),
|
||||||
child: Text(
|
child: Text(
|
||||||
data.name,
|
data.name ?? "",
|
||||||
style: const TextStyle(color: Colors.black, fontSize: 30),
|
style: const TextStyle(color: Colors.black, fontSize: 30),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(4.0),
|
padding: const EdgeInsets.all(4.0),
|
||||||
child: Text(
|
child: Text(
|
||||||
data.description,
|
data.description ?? "",
|
||||||
style: const TextStyle(color: Colors.black, fontSize: 20),
|
style: const TextStyle(color: Colors.black, fontSize: 20),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -9,21 +9,34 @@ const double NORMAL_ICON_SCALE = 2.0;
|
|||||||
const double SCALED_ICON_SCALE = 2.5;
|
const double SCALED_ICON_SCALE = 2.5;
|
||||||
|
|
||||||
class CardPost extends StatefulWidget {
|
class CardPost extends StatefulWidget {
|
||||||
final String description;
|
final String? description;
|
||||||
final String? imageUrl;
|
final String? imageUrl;
|
||||||
final bool isLiked;
|
final bool? isLiked;
|
||||||
final String name;
|
final String? name;
|
||||||
|
final String? surname;
|
||||||
|
|
||||||
final OnLikeCallback onLike;
|
final OnLikeCallback onLike;
|
||||||
final VoidCallback? onTap;
|
final VoidCallback? onTap;
|
||||||
|
|
||||||
const CardPost(this.name, this.description, this.imageUrl, this.isLiked,
|
const CardPost(
|
||||||
this.onLike, this.onTap);
|
{this.name,
|
||||||
|
this.surname,
|
||||||
|
this.description,
|
||||||
|
this.imageUrl,
|
||||||
|
this.isLiked,
|
||||||
|
this.onLike,
|
||||||
|
this.onTap});
|
||||||
|
|
||||||
factory CardPost.fromData(CardPostData data,
|
factory CardPost.fromData(CardPostData data,
|
||||||
{OnLikeCallback onLike, VoidCallback? onTap}) =>
|
{OnLikeCallback onLike, VoidCallback? onTap}) =>
|
||||||
CardPost(data.name, data.description, data.imageUrl, data.isLiked, onLike,
|
CardPost(
|
||||||
onTap);
|
name: data.name,
|
||||||
|
surname: data.surname,
|
||||||
|
description: data.description,
|
||||||
|
imageUrl: data.imageUrl,
|
||||||
|
isLiked: data.isLiked,
|
||||||
|
onLike: onLike,
|
||||||
|
onTap: onTap);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<CardPost> createState() => _CardPostState();
|
State<CardPost> createState() => _CardPostState();
|
||||||
@ -67,7 +80,7 @@ class _CardPostState extends State<CardPost> {
|
|||||||
children: [
|
children: [
|
||||||
Flexible(
|
Flexible(
|
||||||
child: Text(
|
child: Text(
|
||||||
widget.name,
|
(widget.name ?? "") + (" ") + (widget.surname ?? ""),
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
fontSize: 30,
|
fontSize: 30,
|
||||||
@ -83,7 +96,7 @@ class _CardPostState extends State<CardPost> {
|
|||||||
children: [
|
children: [
|
||||||
Flexible(
|
Flexible(
|
||||||
child: Text(
|
child: Text(
|
||||||
widget.description,
|
widget.description ?? "",
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
@ -118,7 +131,7 @@ class _CardPostState extends State<CardPost> {
|
|||||||
iconScale = NORMAL_ICON_SCALE;
|
iconScale = NORMAL_ICON_SCALE;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
widget.onLike?.call(widget.name, isLiked);
|
widget.onLike?.call(widget.name ?? "", isLiked);
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
child: AnimatedScale(
|
child: AnimatedScale(
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:pmu/data/repositories/api_user_repository.dart';
|
||||||
import 'package:pmu/domain/card.dart';
|
import 'package:pmu/domain/card.dart';
|
||||||
import 'package:pmu/presentation/detail_pages/card_detail_page.dart';
|
import 'package:pmu/presentation/detail_pages/card_detail_page.dart';
|
||||||
import 'package:pmu/presentation/home_page/card.dart';
|
import 'package:pmu/presentation/home_page/card.dart';
|
||||||
@ -42,10 +43,7 @@ class Body extends StatelessWidget {
|
|||||||
content: Text(
|
content: Text(
|
||||||
'${isLiked ? 'Вы поставили лайк: ' : 'Вы убрали лайк: '} $title',
|
'${isLiked ? 'Вы поставили лайк: ' : 'Вы убрали лайк: '} $title',
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
color: Colors.black45,
|
color: Colors.black45, fontSize: 20, fontWeight: FontWeight.bold),
|
||||||
fontSize: 20,
|
|
||||||
fontWeight: FontWeight.bold
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
backgroundColor: isLiked ? Colors.green : Colors.red,
|
backgroundColor: isLiked ? Colors.green : Colors.red,
|
||||||
duration: const Duration(seconds: 2),
|
duration: const Duration(seconds: 2),
|
||||||
@ -55,32 +53,24 @@ class Body extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final data = [
|
final data = ApiUserRepository().loadData();
|
||||||
const CardPostData(
|
|
||||||
"Евгения",
|
|
||||||
"Люблю программирование и кататься на скейте",
|
|
||||||
"https://avatar.iran.liara.run/public/girl",
|
|
||||||
false),
|
|
||||||
const CardPostData("Алекс", "Junior Flutter Engineer",
|
|
||||||
"https://avatar.iran.liara.run/public/36", false),
|
|
||||||
const CardPostData(
|
|
||||||
"Станислав",
|
|
||||||
"Нет ничего приятнее прогулки на природе!",
|
|
||||||
"https://avatar.iran.liara.run/public/boy",
|
|
||||||
false),
|
|
||||||
const CardPostData("Вероника", "В свободное время хожу на уроки вокала",
|
|
||||||
"https://avatar.iran.liara.run/public/93", false),
|
|
||||||
];
|
|
||||||
return Center(
|
return Center(
|
||||||
child: SingleChildScrollView(
|
child: FutureBuilder<List<CardPostData>?>(
|
||||||
child: Column(
|
future: data,
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
builder: (context, snapshot) => SingleChildScrollView(
|
||||||
children: data.map((data) {
|
child: snapshot.hasData
|
||||||
return CardPost.fromData(data,
|
? Column(
|
||||||
onLike: (String title, bool isLiked) =>
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
_showSnackBar(context, title, isLiked),
|
children: snapshot.data
|
||||||
onTap: () => _navToDetails(context, data));
|
?.map((data) => CardPost.fromData(data,
|
||||||
}).toList(),
|
onLike: (String title, bool isLiked) =>
|
||||||
)));
|
_showSnackBar(context, title, isLiked),
|
||||||
|
onTap: () => _navToDetails(context, data)))
|
||||||
|
.toList() ??
|
||||||
|
[])
|
||||||
|
: const CircularProgressIndicator(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user