showSnackBar method

void showSnackBar(
  1. String text, {
  2. Duration duration = const Duration(milliseconds: 500),
  3. TextStyle? style,
  4. Color? backgroundColor,
  5. TextDirection? direction,
})

? Show SnackBar from build context

Implementation

void showSnackBar(
  String text, {
  Duration duration = const Duration(milliseconds: 500),
  TextStyle? style,
  Color? backgroundColor,
  TextDirection? direction,
}) {
  try {
    ScaffoldMessenger.of(this).showSnackBar(
      SnackBar(
        backgroundColor: backgroundColor ?? Colors.white,
        content: Text(
          text,
          textDirection: direction,
          style: style ?? const TextStyle(color: Colors.white),
        ),
        duration: duration,
      ),
    );
  } catch (e) {
    Logger('SnackBar').severe(e);
  }
}