forked from eatvio/eatvio_app
fixed layout of diets feed and added text styles
This commit is contained in:
105
lib/core/data/diet/repositories/diet_repository.dart
Normal file
105
lib/core/data/diet/repositories/diet_repository.dart
Normal file
@@ -0,0 +1,105 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:eatvio_app/core/data/diet/services/diet_service.dart';
|
||||
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
class DietRepository {
|
||||
DietRepository({required this.dietsService});
|
||||
final DietService dietsService;
|
||||
|
||||
final _dietLikeStateStreamController = StreamController<DietLikesState>.broadcast();
|
||||
final _dietFavoriteStateStreamController = StreamController<DietFavoriteState>.broadcast();
|
||||
final _dietCommentsStateStreamController = StreamController<DietCommentsState>.broadcast();
|
||||
Stream get dietLikeState => _dietLikeStateStreamController.stream;
|
||||
Stream get dietFavoriteState => _dietFavoriteStateStreamController.stream;
|
||||
Stream get dietCommentsState => _dietCommentsStateStreamController.stream;
|
||||
|
||||
Future<void> likeDiet(int id) async {
|
||||
try {
|
||||
await dietsService.likeDiet(id: id);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<Diet> getDiet(int id) async {
|
||||
try {
|
||||
final diet = await dietsService.getDiet(id: id);
|
||||
return diet;
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> addToFavorite(int id) async {
|
||||
try {
|
||||
await dietsService.addToFavorite(id: id);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> removeFromFavorite(int id) async {
|
||||
try {
|
||||
await dietsService.removeFromFavorite(id: id);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
void emitLikesStateToFeed(DietLikesState state) => _dietLikeStateStreamController.add(state);
|
||||
void emitFavoriteStateToFeed(DietFavoriteState state) => _dietFavoriteStateStreamController.add(state);
|
||||
void emitCommentsStateToFeed(DietCommentsState state) => _dietCommentsStateStreamController.add(state);
|
||||
}
|
||||
|
||||
class DietLikesState extends Equatable {
|
||||
final bool wasLikedByMe;
|
||||
final int totalLikes;
|
||||
final int index;
|
||||
|
||||
DietLikesState({
|
||||
required this.wasLikedByMe,
|
||||
required this.totalLikes,
|
||||
required this.index,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
wasLikedByMe,
|
||||
totalLikes,
|
||||
index,
|
||||
];
|
||||
}
|
||||
|
||||
class DietFavoriteState extends Equatable {
|
||||
final bool isFavorite;
|
||||
final int index;
|
||||
|
||||
DietFavoriteState({
|
||||
required this.isFavorite,
|
||||
required this.index,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
isFavorite,
|
||||
index,
|
||||
];
|
||||
}
|
||||
|
||||
class DietCommentsState extends Equatable {
|
||||
final int index;
|
||||
final int totalComments;
|
||||
|
||||
DietCommentsState({
|
||||
required this.index,
|
||||
required this.totalComments,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
index,
|
||||
totalComments,
|
||||
];
|
||||
}
|
||||
30
lib/core/data/diet/services/diet_service.dart
Normal file
30
lib/core/data/diet/services/diet_service.dart
Normal file
@@ -0,0 +1,30 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
||||
import 'package:retrofit/retrofit.dart';
|
||||
|
||||
part 'diet_service.g.dart';
|
||||
|
||||
@RestApi()
|
||||
abstract class DietService {
|
||||
factory DietService(Dio dio, {String baseUrl}) = _DietService;
|
||||
|
||||
@POST('/api/diets/{id}/like')
|
||||
Future<void> likeDiet({
|
||||
@Path() required int id,
|
||||
});
|
||||
|
||||
@POST('/api/diets/{id}/add_to_favorite')
|
||||
Future<void> addToFavorite({
|
||||
@Path() required int id,
|
||||
});
|
||||
|
||||
@POST('/api/diets/{id}/remove_from_favorite')
|
||||
Future<void> removeFromFavorite({
|
||||
@Path() required int id,
|
||||
});
|
||||
|
||||
@GET('/api/diets/show/{id}')
|
||||
Future<Diet> getDiet({
|
||||
@Path() required int id,
|
||||
});
|
||||
}
|
||||
161
lib/core/data/diet/services/diet_service.g.dart
Normal file
161
lib/core/data/diet/services/diet_service.g.dart
Normal file
@@ -0,0 +1,161 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'diet_service.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RetrofitGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// ignore_for_file: unnecessary_brace_in_string_interps,no_leading_underscores_for_local_identifiers,unused_element,unnecessary_string_interpolations
|
||||
|
||||
class _DietService implements DietService {
|
||||
_DietService(
|
||||
this._dio, {
|
||||
this.baseUrl,
|
||||
this.errorLogger,
|
||||
});
|
||||
|
||||
final Dio _dio;
|
||||
|
||||
String? baseUrl;
|
||||
|
||||
final ParseErrorLogger? errorLogger;
|
||||
|
||||
@override
|
||||
Future<void> likeDiet({required int id}) async {
|
||||
final _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{};
|
||||
final _headers = <String, dynamic>{};
|
||||
const Map<String, dynamic>? _data = null;
|
||||
final _options = _setStreamType<void>(Options(
|
||||
method: 'POST',
|
||||
headers: _headers,
|
||||
extra: _extra,
|
||||
)
|
||||
.compose(
|
||||
_dio.options,
|
||||
'/api/diets/${id}/like',
|
||||
queryParameters: queryParameters,
|
||||
data: _data,
|
||||
)
|
||||
.copyWith(
|
||||
baseUrl: _combineBaseUrls(
|
||||
_dio.options.baseUrl,
|
||||
baseUrl,
|
||||
)));
|
||||
await _dio.fetch<void>(_options);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> addToFavorite({required int id}) async {
|
||||
final _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{};
|
||||
final _headers = <String, dynamic>{};
|
||||
const Map<String, dynamic>? _data = null;
|
||||
final _options = _setStreamType<void>(Options(
|
||||
method: 'POST',
|
||||
headers: _headers,
|
||||
extra: _extra,
|
||||
)
|
||||
.compose(
|
||||
_dio.options,
|
||||
'/api/diets/${id}/add_to_favorite',
|
||||
queryParameters: queryParameters,
|
||||
data: _data,
|
||||
)
|
||||
.copyWith(
|
||||
baseUrl: _combineBaseUrls(
|
||||
_dio.options.baseUrl,
|
||||
baseUrl,
|
||||
)));
|
||||
await _dio.fetch<void>(_options);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> removeFromFavorite({required int id}) async {
|
||||
final _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{};
|
||||
final _headers = <String, dynamic>{};
|
||||
const Map<String, dynamic>? _data = null;
|
||||
final _options = _setStreamType<void>(Options(
|
||||
method: 'POST',
|
||||
headers: _headers,
|
||||
extra: _extra,
|
||||
)
|
||||
.compose(
|
||||
_dio.options,
|
||||
'/api/diets/${id}/remove_from_favorite',
|
||||
queryParameters: queryParameters,
|
||||
data: _data,
|
||||
)
|
||||
.copyWith(
|
||||
baseUrl: _combineBaseUrls(
|
||||
_dio.options.baseUrl,
|
||||
baseUrl,
|
||||
)));
|
||||
await _dio.fetch<void>(_options);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Diet> getDiet({required int id}) async {
|
||||
final _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{};
|
||||
final _headers = <String, dynamic>{};
|
||||
const Map<String, dynamic>? _data = null;
|
||||
final _options = _setStreamType<Diet>(Options(
|
||||
method: 'GET',
|
||||
headers: _headers,
|
||||
extra: _extra,
|
||||
)
|
||||
.compose(
|
||||
_dio.options,
|
||||
'/api/diets/show/${id}',
|
||||
queryParameters: queryParameters,
|
||||
data: _data,
|
||||
)
|
||||
.copyWith(
|
||||
baseUrl: _combineBaseUrls(
|
||||
_dio.options.baseUrl,
|
||||
baseUrl,
|
||||
)));
|
||||
final _result = await _dio.fetch<Map<String, dynamic>>(_options);
|
||||
late Diet _value;
|
||||
try {
|
||||
_value = Diet.fromJson(_result.data!);
|
||||
} on Object catch (e, s) {
|
||||
errorLogger?.logError(e, s, _options);
|
||||
rethrow;
|
||||
}
|
||||
return _value;
|
||||
}
|
||||
|
||||
RequestOptions _setStreamType<T>(RequestOptions requestOptions) {
|
||||
if (T != dynamic &&
|
||||
!(requestOptions.responseType == ResponseType.bytes ||
|
||||
requestOptions.responseType == ResponseType.stream)) {
|
||||
if (T == String) {
|
||||
requestOptions.responseType = ResponseType.plain;
|
||||
} else {
|
||||
requestOptions.responseType = ResponseType.json;
|
||||
}
|
||||
}
|
||||
return requestOptions;
|
||||
}
|
||||
|
||||
String _combineBaseUrls(
|
||||
String dioBaseUrl,
|
||||
String? baseUrl,
|
||||
) {
|
||||
if (baseUrl == null || baseUrl.trim().isEmpty) {
|
||||
return dioBaseUrl;
|
||||
}
|
||||
|
||||
final url = Uri.parse(baseUrl);
|
||||
|
||||
if (url.isAbsolute) {
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
return Uri.parse(dioBaseUrl).resolveUri(url).toString();
|
||||
}
|
||||
}
|
||||
44
lib/core/widgets/bookmark_button.dart
Normal file
44
lib/core/widgets/bookmark_button.dart
Normal file
@@ -0,0 +1,44 @@
|
||||
import 'package:eatvio_app/theme/theme_helper.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class BookmarkButton extends StatelessWidget {
|
||||
const BookmarkButton({
|
||||
super.key,
|
||||
required this.onTap,
|
||||
required this.color,
|
||||
required this.isFavorite,
|
||||
required this.width,
|
||||
required this.height,
|
||||
required this.size,
|
||||
this.shape,
|
||||
this.borderRadius,
|
||||
});
|
||||
final void Function() onTap;
|
||||
final Color color;
|
||||
final BoxShape? shape;
|
||||
final bool isFavorite;
|
||||
final BorderRadiusGeometry? borderRadius;
|
||||
final double width;
|
||||
final double height;
|
||||
final double size;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
width: width,
|
||||
height: height,
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
shape: shape ?? BoxShape.rectangle,
|
||||
borderRadius: borderRadius,
|
||||
),
|
||||
child: Icon(
|
||||
isFavorite ? Icons.bookmark : Icons.bookmark_border_rounded,
|
||||
color: appTheme.black,
|
||||
size: size,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
66
lib/core/widgets/diet_info_row.dart
Normal file
66
lib/core/widgets/diet_info_row.dart
Normal file
@@ -0,0 +1,66 @@
|
||||
import 'package:eatvio_app/core/utils/localization_utils.dart';
|
||||
import 'package:eatvio_app/features/diets/presentation/widgets/info_bouble.dart';
|
||||
import 'package:eatvio_app/features/diets/presentation/widgets/type_badges.dart';
|
||||
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:eatvio_app/theme/custom_text_style.dart';
|
||||
import 'package:eatvio_app/theme/theme_helper.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
|
||||
class DietInfoRow extends StatelessWidget {
|
||||
const DietInfoRow({super.key, required this.diet, this.itemsBackgroundColor, this.disableDescriptionOfTypes = false});
|
||||
final Color? itemsBackgroundColor;
|
||||
final Diet diet;
|
||||
final bool disableDescriptionOfTypes;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = S.of(context);
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: [
|
||||
InfoBouble(
|
||||
backgroundColor: itemsBackgroundColor,
|
||||
children: [
|
||||
SvgPicture.asset(
|
||||
'assets/icons/time2.svg',
|
||||
width: 13.3,
|
||||
height: 13.3,
|
||||
),
|
||||
SizedBox(width: 4),
|
||||
Text(
|
||||
diet.duration.toString() + ' ' + getDayForm(diet.duration, s),
|
||||
style: TextStyles.textXSSemibold.copyWith(color: appTheme.black),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(width: 12),
|
||||
InfoBouble(
|
||||
backgroundColor: itemsBackgroundColor,
|
||||
children: [
|
||||
SvgPicture.asset(
|
||||
'assets/icons/people.svg',
|
||||
width: 13.3,
|
||||
height: 13.3,
|
||||
),
|
||||
SizedBox(width: 4),
|
||||
Text(
|
||||
'80 человек прошли',
|
||||
style: TextStyles.textXSSemibold.copyWith(color: appTheme.black),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(width: 12),
|
||||
InfoBouble(
|
||||
backgroundColor: itemsBackgroundColor,
|
||||
children: [
|
||||
TypeBadges(type: diet.type, disableDescriptionOfTypes: disableDescriptionOfTypes),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
51
lib/core/widgets/feed_icon_button.dart
Normal file
51
lib/core/widgets/feed_icon_button.dart
Normal file
@@ -0,0 +1,51 @@
|
||||
import 'package:eatvio_app/theme/custom_text_style.dart';
|
||||
import 'package:eatvio_app/theme/theme_helper.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
|
||||
class FeedIconButton extends StatelessWidget {
|
||||
const FeedIconButton({super.key, this.icon, this.svgIcon, this.text, this.onTap, this.iconColor, this.backgroundColor, this.textColor});
|
||||
final IconData? icon;
|
||||
final SvgPicture? svgIcon;
|
||||
final String? text;
|
||||
final Function()? onTap;
|
||||
final Color? iconColor;
|
||||
final Color? backgroundColor;
|
||||
final Color? textColor;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return InkWell(
|
||||
onTap: onTap ?? () {},
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 12, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: backgroundColor ?? appTheme.gray100,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
height: 32,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (svgIcon != null) svgIcon!,
|
||||
if (icon != null)
|
||||
Icon(
|
||||
icon,
|
||||
size: 16,
|
||||
color: iconColor ?? appTheme.gray600,
|
||||
),
|
||||
if (text != null) ...[
|
||||
SizedBox(width: 8),
|
||||
Text(
|
||||
text!,
|
||||
style: TextStyles.textSMedium.copyWith(
|
||||
color: textColor ?? appTheme.gray600,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user