pmu_flutter/lec6/lib/view/home_page/card/home_card.dart

82 lines
2.2 KiB
Dart
Raw Normal View History

2024-10-18 01:15:10 +04:00
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:test_app/domain/card.dart';
import 'package:test_app/view/home_page/like_bloc/like_bloc.dart';
import 'package:test_app/view/home_page/like_bloc/like_event.dart';
import 'package:test_app/view/home_page/like_bloc/like_state.dart';
part 'home_card_image.dart';
part 'home_card_like.dart';
part 'home_card_text.dart';
class HomeCard extends StatelessWidget {
final String text;
final String descriptionText;
final String? id;
final String? imageUrl;
final VoidCallback? onTap;
const HomeCard(
this.text, {
super.key,
required this.descriptionText,
this.id,
this.imageUrl,
this.onTap,
});
factory HomeCard.fromData(
CardData data, {
VoidCallback? onTap,
}) =>
HomeCard(
data.text,
descriptionText: data.descriptionText,
id: data.id,
imageUrl: data.imageUrl,
onTap: onTap,
);
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: onTap,
child: Container(
margin: const EdgeInsets.only(top: 8, bottom: 8),
constraints: const BoxConstraints(minHeight: 140),
decoration: BoxDecoration(
color: Colors.white70,
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(.5),
spreadRadius: 4,
offset: const Offset(0, 5),
blurRadius: 8,
),
],
),
child: IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_CardImage(imageUrl ?? ''),
_CardText(
text,
descriptionText: descriptionText,
),
BlocBuilder<LikeBloc, LikeState>(builder: (context, likeState) {
return _CardLike(
text,
id: id,
isLiked: likeState.likedIds?.contains(id) == true,
);
}),
],
),
),
),
);
}
}