add loading

This commit is contained in:
Phuoc Nguyen
2025-10-28 17:41:31 +07:00
parent 4b35d236df
commit 73b77c27de
40 changed files with 122 additions and 131 deletions

View File

@@ -28,6 +28,7 @@ class _ProductsPageState extends ConsumerState<ProductsPage>
with SingleTickerProviderStateMixin {
late TabController _tabController;
String _currentOperationType = 'import';
bool _isTabSwitching = false;
@override
void initState() {
@@ -52,6 +53,7 @@ class _ProductsPageState extends ConsumerState<ProductsPage>
if (_currentOperationType != newOperationType) {
setState(() {
_currentOperationType = newOperationType;
_isTabSwitching = true; // Mark that tab is switching
});
// Load products for new operation type
@@ -230,6 +232,18 @@ class _ProductsPageState extends ConsumerState<ProductsPage>
final isLoading = productsState.isLoading;
final error = productsState.error;
// Listen to products state changes to clear tab switching flag
ref.listen(productsProvider, (previous, next) {
// Clear tab switching flag when loading completes
if (previous?.isLoading == true && next.isLoading == false) {
if (_isTabSwitching) {
setState(() {
_isTabSwitching = false;
});
}
}
});
return Scaffold(
appBar: AppBar(
title: Column(
@@ -361,8 +375,10 @@ class _ProductsPageState extends ConsumerState<ProductsPage>
required List products,
required ThemeData theme,
}) {
// Loading state
if (isLoading && products.isEmpty) {
// Loading state - show when:
// 1. Loading and no products, OR
// 2. Tab is switching (loading new products for different operation type)
if (isLoading && (products.isEmpty || _isTabSwitching)) {
return const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,