Лаба 7, починила лайки
This commit is contained in:
parent
d707eff870
commit
77ed129792
@ -1,6 +1,6 @@
|
|||||||
part of 'home_page.dart';
|
part of 'home_page.dart';
|
||||||
|
|
||||||
typedef OnLikeCallBack = void Function(int? id, String title, bool isLiked)?;
|
typedef OnLikeCallBack = void Function(String? id, String title, bool isLiked)?;
|
||||||
|
|
||||||
class _Card extends StatelessWidget {
|
class _Card extends StatelessWidget {
|
||||||
final String text;
|
final String text;
|
||||||
@ -9,7 +9,7 @@ class _Card extends StatelessWidget {
|
|||||||
final String? imageUrl;
|
final String? imageUrl;
|
||||||
final OnLikeCallBack onLike;
|
final OnLikeCallBack onLike;
|
||||||
final VoidCallback? onTap;
|
final VoidCallback? onTap;
|
||||||
final int? id;
|
final String? id;
|
||||||
final bool isLiked;
|
final bool isLiked;
|
||||||
|
|
||||||
const _Card(this.text, {
|
const _Card(this.text, {
|
||||||
@ -35,7 +35,7 @@ class _Card extends StatelessWidget {
|
|||||||
onLike: onLike,
|
onLike: onLike,
|
||||||
onTap: onTap,
|
onTap: onTap,
|
||||||
isLiked: isLiked,
|
isLiked: isLiked,
|
||||||
id: data.id,
|
id: data.id.toString()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ class _BodyState extends State<Body> {
|
|||||||
? _Card.fromData(
|
? _Card.fromData(
|
||||||
data,
|
data,
|
||||||
onLike: _onLike,
|
onLike: _onLike,
|
||||||
isLiked: likeState.likedIds?.contains(data.id) == true,
|
isLiked: likeState.likedIds?.contains(data.id.toString()) == true,
|
||||||
onTap: () => _navToDetails(context, data),
|
onTap: () => _navToDetails(context, data),
|
||||||
)
|
)
|
||||||
: const SizedBox.shrink();
|
: const SizedBox.shrink();
|
||||||
@ -186,7 +186,7 @@ class _BodyState extends State<Body> {
|
|||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||||
content: Text(
|
content: Text(
|
||||||
'$title ${isLiked ? context.locale.liked : context.locale.disliked}',
|
'$title ${isLiked ? context.locale.disliked : context.locale.liked}',
|
||||||
style: Theme.of(context).textTheme.bodyLarge,
|
style: Theme.of(context).textTheme.bodyLarge,
|
||||||
),
|
),
|
||||||
backgroundColor: Color(0xFFFFFFFF),
|
backgroundColor: Color(0xFFFFFFFF),
|
||||||
@ -195,11 +195,10 @@ class _BodyState extends State<Body> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onLike(int? 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));
|
||||||
_showSnackBar(context, title, isLiked);
|
_showSnackBar(context, title, isLiked);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,10 +22,7 @@ class LikeBloc extends Bloc<LikeEvent, LikeState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _onChangeLike(ChangeLikeEvent event, Emitter<LikeState> emit) async{
|
FutureOr<void> _onChangeLike(ChangeLikeEvent event, Emitter<LikeState> emit) async{
|
||||||
final updatedListInt = List<int>.from(state.likedIds ?? []);
|
final updatedList = List<String>.from(state.likedIds ?? []);
|
||||||
print(updatedListInt);
|
|
||||||
final updatedList = updatedListInt.map((int number) => number.toString()).toList();
|
|
||||||
print(updatedList);
|
|
||||||
|
|
||||||
if (updatedList.contains(event.id.toString())) {
|
if (updatedList.contains(event.id.toString())) {
|
||||||
updatedList.remove(event.id.toString());
|
updatedList.remove(event.id.toString());
|
||||||
|
@ -7,7 +7,7 @@ class LoadLikesEvent extends LikeEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ChangeLikeEvent extends LikeEvent {
|
class ChangeLikeEvent extends LikeEvent {
|
||||||
final int id;
|
final String id;
|
||||||
|
|
||||||
const ChangeLikeEvent(this.id);
|
const ChangeLikeEvent(this.id);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user