mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
Refactor AddDeviceTypeWidget for Improved Error Handling and Loading States:
- Extracted loading and error handling logic into separate methods for better readability and maintainability. - Updated UI to utilize centralized loading and failure widgets, enhancing user experience during data fetching.
This commit is contained in:
@ -21,22 +21,14 @@ class AddDeviceTypeWidget extends StatelessWidget {
|
|||||||
backgroundColor: ColorsManager.whiteColors,
|
backgroundColor: ColorsManager.whiteColors,
|
||||||
content: BlocBuilder<ProductsBloc, ProductsState>(
|
content: BlocBuilder<ProductsBloc, ProductsState>(
|
||||||
builder: (context, state) => switch (state) {
|
builder: (context, state) => switch (state) {
|
||||||
ProductsInitial() => const Center(
|
ProductsInitial() => _buildLoading(context),
|
||||||
child: CircularProgressIndicator(),
|
ProductsLoading() => _buildLoading(context),
|
||||||
),
|
|
||||||
ProductsLoading() => const Center(
|
|
||||||
child: CircularProgressIndicator(),
|
|
||||||
),
|
|
||||||
ProductsLoaded(:final products) => ProductsGrid(
|
ProductsLoaded(:final products) => ProductsGrid(
|
||||||
products: products,
|
products: products,
|
||||||
),
|
),
|
||||||
ProductsFailure(:final errorMessage) => Center(
|
ProductsFailure(:final errorMessage) => _buildFailure(
|
||||||
child: Text(
|
context,
|
||||||
errorMessage,
|
errorMessage,
|
||||||
style: context.textTheme.bodyMedium?.copyWith(
|
|
||||||
color: context.theme.colorScheme.error,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -44,4 +36,25 @@ class AddDeviceTypeWidget extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildLoading(BuildContext context) => SizedBox(
|
||||||
|
width: context.screenWidth * 0.9,
|
||||||
|
height: context.screenHeight * 0.65,
|
||||||
|
child: const Center(child: CircularProgressIndicator()),
|
||||||
|
);
|
||||||
|
|
||||||
|
Widget _buildFailure(BuildContext context, String errorMessage) {
|
||||||
|
return SizedBox(
|
||||||
|
width: context.screenWidth * 0.9,
|
||||||
|
height: context.screenHeight * 0.65,
|
||||||
|
child: Center(
|
||||||
|
child: SelectableText(
|
||||||
|
errorMessage,
|
||||||
|
style: context.textTheme.bodyMedium?.copyWith(
|
||||||
|
color: context.theme.colorScheme.error,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user