93 lines
2.5 KiB
Dart
93 lines
2.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../../../core/theme/app_colors.dart';
|
|
import '../../../core/theme/app_spacing.dart';
|
|
import '../../../core/theme/app_typography.dart';
|
|
import '../models/category_item.dart';
|
|
|
|
/// Tab row for home screen - 使用分类列表接口数据
|
|
class HomeTabRow extends StatelessWidget {
|
|
const HomeTabRow({
|
|
super.key,
|
|
required this.categories,
|
|
required this.selectedId,
|
|
required this.onTabChanged,
|
|
});
|
|
|
|
final List<CategoryItem> categories;
|
|
final int selectedId;
|
|
final ValueChanged<CategoryItem> onTabChanged;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SizedBox(
|
|
height: 40,
|
|
child: SingleChildScrollView(
|
|
scrollDirection: Axis.horizontal,
|
|
padding: const EdgeInsets.symmetric(vertical: 4),
|
|
child: Row(
|
|
children: [
|
|
for (var i = 0; i < categories.length; i++) ...[
|
|
if (i > 0) const SizedBox(width: AppSpacing.md),
|
|
_TabChip(
|
|
label: categories[i].name,
|
|
isSelected: selectedId == categories[i].id,
|
|
onTap: () => onTabChanged(categories[i]),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _TabChip extends StatelessWidget {
|
|
const _TabChip({
|
|
required this.label,
|
|
required this.isSelected,
|
|
required this.onTap,
|
|
});
|
|
|
|
final String label;
|
|
final bool isSelected;
|
|
final VoidCallback onTap;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return GestureDetector(
|
|
onTap: onTap,
|
|
child: Container(
|
|
height: 32,
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 14,
|
|
vertical: 6,
|
|
),
|
|
decoration: BoxDecoration(
|
|
color: isSelected ? AppColors.primary : AppColors.surfaceAlt,
|
|
borderRadius: BorderRadius.circular(20),
|
|
border: isSelected ? null : Border.all(color: AppColors.border),
|
|
boxShadow: isSelected
|
|
? [
|
|
BoxShadow(
|
|
color: AppColors.primaryShadow.withValues(alpha: 0.19),
|
|
blurRadius: 4,
|
|
offset: const Offset(0, 2),
|
|
),
|
|
]
|
|
: null,
|
|
),
|
|
child: Center(
|
|
child: Text(
|
|
label,
|
|
style: AppTypography.bodySmall.copyWith(
|
|
color: isSelected ? AppColors.surface : AppColors.textSecondary,
|
|
fontWeight: isSelected ? FontWeight.w600 : FontWeight.w500,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|