buildLoadingOverlay method
Widget
buildLoadingOverlay({
- required Widget child,
- String? loadingKey = LoadingKey.global,
- Widget? loadingWidget,
- Duration timeout = const Duration(seconds: 30),
override
Implementation
@override
Widget buildLoadingOverlay({
required Widget child,
String? loadingKey = LoadingKey.global,
Widget? loadingWidget,
Duration timeout = const Duration(seconds: 30),
}) {
return BlocBuilder<CommonBloc, CommonState>(
buildWhen:
(previous, current) =>
previous.isLoading(key: loadingKey) !=
current.isLoading(key: loadingKey),
builder: (context, state) {
if (state.isLoading(key: loadingKey)) {
Future.delayed(timeout, () {
final currentContext = context;
if (currentContext.mounted && state.isLoading(key: loadingKey)) {
hideLoading(key: loadingKey);
}
});
}
return Stack(
children: [
child,
if (state.isLoading(key: loadingKey))
AnimatedOpacity(
opacity: state.isLoading(key: loadingKey) ? 1.0 : 0.0,
duration: const Duration(milliseconds: 300),
curve: Curves.easeInOut,
child: loadingWidget ?? buildPageLoading(),
),
],
);
},
);
}