mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 22:57:21 +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,
|
||||
content: BlocBuilder<ProductsBloc, ProductsState>(
|
||||
builder: (context, state) => switch (state) {
|
||||
ProductsInitial() => const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
ProductsLoading() => const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
ProductsInitial() => _buildLoading(context),
|
||||
ProductsLoading() => _buildLoading(context),
|
||||
ProductsLoaded(:final products) => ProductsGrid(
|
||||
products: products,
|
||||
),
|
||||
ProductsFailure(:final errorMessage) => Center(
|
||||
child: Text(
|
||||
errorMessage,
|
||||
style: context.textTheme.bodyMedium?.copyWith(
|
||||
color: context.theme.colorScheme.error,
|
||||
),
|
||||
),
|
||||
ProductsFailure(:final errorMessage) => _buildFailure(
|
||||
context,
|
||||
errorMessage,
|
||||
),
|
||||
},
|
||||
),
|
||||
@ -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