processHttpsCallableResult method

bool processHttpsCallableResult(
  1. HttpsCallableResult result
)

Shows a snackbar with the result of a Cloud Function call.

The result is expected to be a map with a single key-value pair, where the key is either 'error' or 'success'. The value is the message to show.

Returns whether the call was successful.

Implementation

bool processHttpsCallableResult(HttpsCallableResult result) {
  final data = (result.data as Map<String, dynamic>).entries.first;
  final success = data.key != 'error';
  ScaffoldMessenger.of(this).showSnackBar(
    SnackBar(
      content: Text(
        data.value.toString(),
        style: TextStyle(
          color: success
              ? Theme.of(this).snackBarTheme.contentTextStyle?.color
              : Theme.of(this).colorScheme.onErrorContainer,
        ),
      ),
      backgroundColor: success
          ? Theme.of(this).snackBarTheme.backgroundColor
          : Theme.of(this).colorScheme.errorContainer,
    ),
  );
  return success;
}