saveVital function
Future<void>
saveVital({
- required BuildContext context,
- required Map<
String, dynamic> data, - required String successMsg,
- bool shouldPop = true,
Saves a vital by calling the graphQL endpoint using the variables provided
in the form of a Map<String, dynamic> data
This function checks the returned value of the result and performs the following:
-
updates the
ExamChangeObject().onAddVitalListener
listener with the value oftrue
so that the UI can rebuild, and then closes the drawer -
if an update was unsuccessful, it updates the the
ExamChangeObject().onAddVitalListener
listener with the value offalse
so that the UI does not rebuild
PARAMS:
BuildContext context
- the build context which is necessary for making the API callMap<String, dynamic> data
- the mutation variables to be used to make the API callString successMsg
- the success message to show if a vital was saved successfullybool shouldPop = true
- whether to close the current drawer or not. The value is set totrue
by default because this function will always close the drawer
Implementation
Future<void> saveVital(
{required BuildContext context,
required Map<String, dynamic> data,
required String successMsg,
bool shouldPop = true}) async {
/// Save systolic blood pressure
final Map<String, dynamic>? result = await showDialog<Map<String, dynamic>>(
context: context,
useRootNavigator: false,
barrierDismissible: false,
builder: (BuildContext context) {
return BewellSubmitDialog(data: data, query: addVitalsMutation);
},
);
if (result != null) {
if (result['createFHIRObservation'] != null) {
ExamChangeObject().onAddVitalListener.add(true);
/// Close drawer
if (shouldPop) Navigator.of(context).pop();
ScaffoldMessenger.of(context)
..hideCurrentSnackBar()
..showSnackBar(SnackBar(
content: Text(successMsg),
duration: const Duration(seconds: kShortSnackBarDuration),
));
} else {
ExamChangeObject().onAddVitalListener.add(false);
}
}
}