exceptionHandlerWithDialog function
Future<void>
exceptionHandlerWithDialog({
- required BuildContext context,
- required dynamic e,
- bool handleTimeout = true,
Implementation
Future<void> exceptionHandlerWithDialog(
{required BuildContext context,
required dynamic e,
bool handleTimeout = true}) async {
if (e is SocketException) {
await showModalBottomSheet(
isScrollControlled: true,
backgroundColor: Colors.transparent,
constraints: const BoxConstraints(
maxWidth: double.infinity,
),
context: context,
builder: (context) {
return Padding(
padding: MediaQuery.of(context).viewInsets,
child: ErrorModalWidget(
message: '😌 You do not have access to the internet',
),
);
},
);
} else if (e is TimeoutException && handleTimeout == true) {
await showModalBottomSheet(
isScrollControlled: true,
backgroundColor: Colors.transparent,
constraints: const BoxConstraints(
maxWidth: double.infinity,
),
context: context,
builder: (context) {
return Padding(
padding: MediaQuery.of(context).viewInsets,
child: ErrorModalWidget(
message: 'There seems to be a connection issue. Please try again shortly',
),
);
},
);
} else {
// On any other exception
await showModalBottomSheet(
isScrollControlled: true,
backgroundColor: Colors.transparent,
constraints: const BoxConstraints(
maxWidth: double.infinity,
),
context: context,
builder: (context) {
return Padding(
padding: MediaQuery.of(context).viewInsets,
child: ErrorModalWidget(),
);
},
);
}
}