proxybuy-flutter/lib/screens/product/item.dart

224 lines
6.9 KiB
Dart

// ignore_for_file: must_be_immutable, deprecated_member_use
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:lba/gen/assets.gen.dart';
import 'package:lba/res/colors.dart';
import 'package:lba/widgets/buildWarpedInfo.dart';
import 'package:lba/widgets/orderType.dart';
import 'package:lba/widgets/rate.dart';
import 'package:lba/widgets/reviews.dart';
class Item extends StatefulWidget {
String title;
String brand;
String dimensions;
String colour;
String material;
String description;
Item({
super.key,
required this.title,
required this.brand,
required this.dimensions,
required this.colour,
required this.material,
required this.description,
});
@override
State<Item> createState() => _ItemState();
}
class _ItemState extends State<Item> with TickerProviderStateMixin {
bool showAllReviews = false;
final GlobalKey<AnimatedListState> _listKey = GlobalKey<AnimatedListState>();
final List<Map<String, dynamic>> reviews = [
{
"name": "Sara M",
"comment":
'"Super happy with my new sofa from Chattels & More! 🙻✨ Great quality, smooth delivery, and helpful staff. Totally worth it!" 😍👌',
"rate": 5.0,
"yesCount": 2,
"noCount": 0,
"date": "Jun 09, 2025",
},
{
"name": "Khalid A",
"comment":
'"Nice design but poor delivery experience 😕🕐 Had to wait extra days and deal with missing parts. Expected better for the price." 👎💸',
"rate": 1.0,
"yesCount": 5,
"noCount": 10,
"date": "Dec 26, 2024",
},
{
"name": "Khalid A",
"comment":
'"Nice design but poor delivery experience 😕🕐 Had to wait extra days and deal with missing parts. Expected better for the price." 👎💸',
"rate": 3.0,
"yesCount": 5,
"noCount": 10,
"date": "Dec 26, 2024",
},
{
"name": "Sara M",
"comment":
'"Super happy with my new sofa from Chattels & More! 🙻✨ Great quality, smooth delivery, and helpful staff. Totally worth it!" 😍👌',
"rate": 4.0,
"yesCount": 2,
"noCount": 0,
"date": "Jun 09, 2025",
},
];
List<Map<String, dynamic>> displayedReviews = [];
@override
void initState() {
super.initState();
displayedReviews = reviews.length > 2 ? reviews.sublist(0, 2) : List.from(reviews);
}
void _showAllReviewsWithAnimation() async {
final newItems = reviews.sublist(displayedReviews.length);
for (int i = 0; i < newItems.length; i++) {
await Future.delayed(Duration(milliseconds: 150));
displayedReviews.add(newItems[i]);
_listKey.currentState?.insertItem(displayedReviews.length - 1);
setState(() {});
}
setState(() {
showAllReviews = true;
});
}
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(16.0),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Align(
alignment: Alignment.centerLeft,
child: Text(
widget.title,
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
),
),
SizedBox(height: 5),
Row(
children: [
Text("Brand: "),
Expanded(
child: Text(
widget.brand,
style: TextStyle(color: LightAppColors.primary),
overflow: TextOverflow.ellipsis,
),
),
],
),
SizedBox(height: 10),
Row(
children: [
CustomStarRating(rating: 4.8),
SizedBox(width: 3),
Text(
"4.8",
style: TextStyle(color: LightAppColors.productDetailDivider),
),
],
),
SizedBox(height: 15),
Row(
children: [
OrderType(
icon: Assets.icons.cardPos.path,
typename: "Delivery",
fill: true,
),
SizedBox(width: 7),
OrderType(
icon: Assets.icons.shoppingCart.path,
typename: "Pickup",
fill: true,
),
],
),
SizedBox(height: 15),
buildWrappedInfo("Dimensions:", widget.dimensions),
buildWrappedInfo("Colour:", widget.colour),
buildWrappedInfo("Material:", widget.material),
buildWrappedInfo("Description:", widget.description),
SizedBox(height: 30),
Center(
child: Text(
"Top reviews from the United Arab Emirates",
style: TextStyle(fontWeight: FontWeight.bold),
),
),
SizedBox(height: 15),
AnimatedList(
key: _listKey,
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
initialItemCount: displayedReviews.length,
itemBuilder: (context, index, animation) {
final review = displayedReviews[index];
return SizeTransition(
sizeFactor: animation,
axisAlignment: -1,
child: Reviews(
name: review['name'],
comment: review['comment'],
rate: review['rate'],
yesCount: review['yesCount'],
noCount: review['noCount'],
date: review['date'],
),
);
},
),
if (!showAllReviews && reviews.length > 2)
Column(
children: [
Center(
child: InkWell(
onTap: _showAllReviewsWithAnimation,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"See all reviews",
style: TextStyle(
color: LightAppColors.allReviewOpener,
fontWeight: FontWeight.bold,
fontSize: 18,
),
),
SizedBox(width: 10),
SvgPicture.asset(
Assets.icons.arrowDown.path,
color: LightAppColors.allReviewOpener,
),
],
),
),
),
SizedBox(height: 50,)
],
),
],
),
),
);
}
}