displayError static method

void displayError({
  1. required BuildContext context,
  2. required String message,
  3. VoidCallback? retryCallback,
})

Implementation

static void displayError({
  required BuildContext context,
  required String message,
  VoidCallback? retryCallback,
}) {
  final snackBar = SnackBar(
    content: Text(message),
    backgroundColor: Colors.red,
    duration: const Duration(seconds: 30),
    action: retryCallback != null
        ? SnackBarAction(
      label: 'Retry',
      textColor: Colors.white,
      onPressed: retryCallback,
    )
        : SnackBarAction(
      label: 'Close',
      textColor: Colors.white,
      onPressed: () {},
    ),
  );

  // Find the Scaffold in the widget tree and use it to show a SnackBar.
  ScaffoldMessenger.of(context).showSnackBar(snackBar);
}