aboutsummaryrefslogtreecommitdiff
path: root/lib/widgets/toastbar_widget.dart
blob: 35068df03ca3928dc87048f13a0f3b1b6d42700e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import 'package:flutter/material.dart';

class ToastBar {
  static Future<void> showToastBar(BuildContext context, String content, {bool error = false, String? actionLabel, Function? actionCallback}) async {
    SnackBar snackBar = SnackBar(
      action: actionLabel != ""
          ? SnackBarAction(
              label: actionLabel!,
              onPressed: () {
                if (actionCallback != null) actionCallback();
              },
              textColor: Theme.of(context).colorScheme.secondary)
          : null,
      backgroundColor: error == true ? Colors.red : Colors.grey[900],
      behavior: SnackBarBehavior.floating,
      duration: const Duration(seconds: 5),
      elevation: 5.0,
      content: Text(
        content,
        style: const TextStyle(color: Colors.white),
        overflow: TextOverflow.ellipsis,
      ),
    );

    ScaffoldMessenger.of(context).showSnackBar(snackBar);
  }
}