menu page
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import '../../../common/theme/theme.dart';
|
||||
import '../../../sample/product_sample_data.dart';
|
||||
|
||||
class SliverCategoryDelegate extends SliverPersistentHeaderDelegate {
|
||||
final List<ProductCategory> categories;
|
||||
final String selectedCategoryId;
|
||||
final Function(String) onCategoryTap;
|
||||
|
||||
SliverCategoryDelegate({
|
||||
required this.categories,
|
||||
required this.selectedCategoryId,
|
||||
required this.onCategoryTap,
|
||||
});
|
||||
|
||||
@override
|
||||
double get minExtent => 60;
|
||||
|
||||
@override
|
||||
double get maxExtent => 60;
|
||||
|
||||
@override
|
||||
Widget build(
|
||||
BuildContext context,
|
||||
double shrinkOffset,
|
||||
bool overlapsContent,
|
||||
) {
|
||||
return Container(
|
||||
height: 60,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.surface,
|
||||
border: Border(
|
||||
bottom: BorderSide(color: AppColor.borderLight, width: 1),
|
||||
),
|
||||
),
|
||||
child: ListView.builder(
|
||||
scrollDirection: Axis.horizontal,
|
||||
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
itemCount: categories.length,
|
||||
itemBuilder: (context, index) {
|
||||
final category = categories[index];
|
||||
final isSelected = category.id == selectedCategoryId;
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () => onCategoryTap(category.id),
|
||||
child: Container(
|
||||
margin: EdgeInsets.only(right: 12),
|
||||
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected ? AppColor.primary : AppColor.backgroundLight,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(
|
||||
color: isSelected ? AppColor.primary : AppColor.border,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(category.icon, style: AppStyle.md),
|
||||
SizedBox(width: 8),
|
||||
Text(
|
||||
category.name,
|
||||
style: AppStyle.md.copyWith(
|
||||
color: isSelected
|
||||
? AppColor.textWhite
|
||||
: AppColor.textPrimary,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
SizedBox(width: 4),
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? AppColor.textWhite.withOpacity(0.2)
|
||||
: AppColor.primary.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Text(
|
||||
"${category.productCount}",
|
||||
style: AppStyle.xs.copyWith(
|
||||
color: isSelected
|
||||
? AppColor.textWhite
|
||||
: AppColor.primary,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRebuild(covariant SliverPersistentHeaderDelegate oldDelegate) {
|
||||
return oldDelegate is SliverCategoryDelegate &&
|
||||
(oldDelegate.selectedCategoryId != selectedCategoryId ||
|
||||
oldDelegate.categories != categories);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user