saveVital function

Future<void> saveVital({
  1. required BuildContext context,
  2. required Map<String, dynamic> data,
  3. required String successMsg,
  4. 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 of true 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 of false so that the UI does not rebuild

PARAMS:

  1. BuildContext context - the build context which is necessary for making the API call
  2. Map<String, dynamic> data - the mutation variables to be used to make the API call
  3. String successMsg - the success message to show if a vital was saved successfully
  4. bool shouldPop = true - whether to close the current drawer or not. The value is set to true 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);
    }
  }
}