fix category tabbar
This commit is contained in:
parent
613b216c04
commit
1fbacae1f4
@ -60,13 +60,13 @@ class CategoryLoaderBloc
|
|||||||
},
|
},
|
||||||
(response) async {
|
(response) async {
|
||||||
final categories = response.data.categories;
|
final categories = response.data.categories;
|
||||||
|
categories.insert(0, CategoryModel.all());
|
||||||
|
|
||||||
final totalPages = response.data.totalPages;
|
final totalPages = response.data.totalPages;
|
||||||
final hasReachedMax = categories.length < 10 || 1 >= totalPages;
|
final hasReachedMax = categories.length < 10 || 1 >= totalPages;
|
||||||
|
|
||||||
log('✅ Categories loaded: ${categories.length}, hasReachedMax: $hasReachedMax');
|
log('✅ Categories loaded: ${categories.length}, hasReachedMax: $hasReachedMax');
|
||||||
|
|
||||||
categories.insert(0, CategoryModel.all());
|
|
||||||
|
|
||||||
emit(CategoryLoaderState.loaded(
|
emit(CategoryLoaderState.loaded(
|
||||||
categories: categories,
|
categories: categories,
|
||||||
hasReachedMax: hasReachedMax,
|
hasReachedMax: hasReachedMax,
|
||||||
|
|||||||
@ -228,6 +228,7 @@ class _HomePageState extends State<HomePage> {
|
|||||||
child: BlocBuilder<ProductLoaderBloc, ProductLoaderState>(
|
child: BlocBuilder<ProductLoaderBloc, ProductLoaderState>(
|
||||||
builder: (context, productState) {
|
builder: (context, productState) {
|
||||||
return CategoryTabBar(
|
return CategoryTabBar(
|
||||||
|
key: ValueKey(categories.length),
|
||||||
categories: categories,
|
categories: categories,
|
||||||
tabViews: categories.map((category) {
|
tabViews: categories.map((category) {
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
|
|||||||
@ -41,6 +41,36 @@ class _CategoryTabBarState extends State<CategoryTabBar>
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didUpdateWidget(CategoryTabBar oldWidget) {
|
||||||
|
super.didUpdateWidget(oldWidget);
|
||||||
|
|
||||||
|
// ✅ Update TabController when categories length changes
|
||||||
|
if (oldWidget.categories.length != widget.categories.length) {
|
||||||
|
_tabController.dispose();
|
||||||
|
_tabController = TabController(
|
||||||
|
length: widget.categories.length,
|
||||||
|
vsync: this,
|
||||||
|
initialIndex: 0, // Reset to first tab
|
||||||
|
);
|
||||||
|
|
||||||
|
_tabController.addListener(() {
|
||||||
|
if (_tabController.indexIsChanging) {
|
||||||
|
if (_tabController.index == 0) {
|
||||||
|
context.read<ProductLoaderBloc>().add(
|
||||||
|
ProductLoaderEvent.getProduct(),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
selectedCategoryId = widget.categories[_tabController.index].id;
|
||||||
|
context.read<ProductLoaderBloc>().add(
|
||||||
|
ProductLoaderEvent.getProduct(categoryId: selectedCategoryId),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_tabController.dispose();
|
_tabController.dispose();
|
||||||
|
|||||||
@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
|
|||||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||||
# In Windows, build-name is used as the major, minor, and patch parts
|
# In Windows, build-name is used as the major, minor, and patch parts
|
||||||
# of the product and file versions while build-number is used as the build suffix.
|
# of the product and file versions while build-number is used as the build suffix.
|
||||||
version: 1.0.2+4
|
version: 1.0.2+5
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=3.2.4 <4.0.0"
|
sdk: ">=3.2.4 <4.0.0"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user