add loading
This commit is contained in:
@@ -62,10 +62,16 @@ class _LoginPageState extends ConsumerState<LoginPage> {
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
// App logo/icon
|
||||
Icon(
|
||||
Icons.warehouse_outlined,
|
||||
size: 80,
|
||||
color: theme.colorScheme.primary,
|
||||
Center(
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: Image.asset(
|
||||
'assets/app_icon.jpg',
|
||||
width: 100,
|
||||
height: 100,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user