showLoader<T> method
Shows a loader dialog with optional timeout and back button handling.
The enableTimeOut parameter determines whether to enable the
timeout functionality.
The timeOut parameter sets the duration of the timeout in milliseconds.
The canPop parameter determines if the dialog can be closed by
pressing the back button.
Implementation
Future<void> showLoader<T>({
bool enableTimeOut = false,
int timeOut = 5000,
bool canPop = false,
Widget? child,
}) async {
_loading = true;
if (enableTimeOut) {
Future<void>.delayed(
Duration(milliseconds: timeOut),
() => hideLoader(),
);
}
await showDialog<T>(
context: this,
barrierDismissible: false,
builder: (BuildContext context) {
dialogCtx = context;
return PopScope(
canPop: canPop,
onPopInvokedWithResult: (didPop, _) {
if (!didPop) return;
_loading = false;
},
child: child ??
Center(
child: Container(
height: 80,
width: 80,
decoration: BoxDecoration(
color: isDarkMode ? Colors.white : Colors.black,
borderRadius: BorderRadius.circular(15),
),
child: FractionallySizedBox(
widthFactor: 0.5,
heightFactor: 0.5,
child: CircularProgressIndicator(
strokeWidth: 2.5,
color: isDarkMode ? Colors.black : Colors.white,
// valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
),
),
),
),
);
},
);
}