handle method

  1. @override
Future<bool> handle(
  1. Report error,
  2. BuildContext? context
)
override

Handle report. If there's scaffold messenger in provided context, then snackbar will be shown.

Implementation

@override
Future<bool> handle(Report error, BuildContext? context) async {
  try {
    if (!_hasScaffoldMessenger(context!)) {
      _printLog('Passed context has no ScaffoldMessenger in widget ancestor');
      return false;
    }

    ScaffoldMessenger.of(context).showSnackBar(
      SnackBar(
        content: Text(
          _getErrorMessage(error),
          style: textStyle,
        ),
        backgroundColor: backgroundColor,
        elevation: elevation,
        margin: margin,
        padding: padding,
        width: width,
        shape: shape,
        action: action,
        duration: duration,
        animation: animation,
        behavior: behavior,
        onVisible: onVisible,
      ),
    );
    return true;
  } catch (exception, stackTrace) {
    _printLog('Failed to show snackbar: $exception, $stackTrace');
    return false;
  }
}