checkData function
void
checkData({})
checkData checks the validity of the data returned from the api and proceeds if successful or shows an error message if there are any errors
variables passed in are custom
data
- the data to be checked against
context
- the context
successMsg
- the message to be displayed on successful completion
errorMsg
- the message to be displayed in case of any error
listeners
- the listener to be updated
listenerValue
- the value to update the listener with
Implementation
void checkData({
required dynamic data,
required BuildContext context,
required String successMsg,
required String errorMsg,
required BehaviorSubject<bool> listener,
required bool listenerValue,
required bool popContext,
required Function? successCallback,
}) {
if (data != null) {
/// Update listeners
listener.add(listenerValue);
/// Close drawer
if (popContext) {
Navigator.pop(context);
/// Success feedback
ScaffoldMessenger.of(context)
..hideCurrentSnackBar()
..showSnackBar(SnackBar(
content: Text(successMsg), duration: const Duration(seconds: 5)));
} else if (successCallback != null) {
successCallback();
/// Success feedback
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(successMsg), duration: const Duration(seconds: 5)));
}
return;
} else {
/// Notify the user of the error
ScaffoldMessenger.of(context)
..hideCurrentSnackBar()
..showSnackBar(SnackBar(
content: Text(errorMsg), duration: const Duration(seconds: 10)));
}
}