showScaffoldMessage function

Future<bool> showScaffoldMessage(
  1. String message,
  2. BuildContext context,
  3. String type, [
  4. bool waitForOk = true,
])

Implementation

Future<bool> showScaffoldMessage(
  String message,
  BuildContext context,
  String type, [
  bool waitForOk = true,
]) {
  final AppCallablesSuper appCallables = appCallablesLocator
      .get<AppCallablesSuper>();
  final Completer<bool> response = Completer<bool>();
  final scaffoldMessenger = ScaffoldMessenger.of(context);
  final snackBar = SnackBar(
    shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)),
    backgroundColor: type == typeError
        ? Colors.red[900]
        : type == typeInfo
        ? Colors.lightBlue
        : Colors.blueGrey[900],
    behavior: SnackBarBehavior.floating,
    // Stay until user clicks 'Close' or Close automatically after defaultDuration
    duration: waitForOk ? const Duration(days: 365) : defaultDuration,
    content: appCallables.getThemeParams()['closeButtonPlacement'] == "bottom"
        ? Column(
            children: [
              Text(
                message,
                style: TextStyle(
                  color: type == typeError
                      ? Colors.white
                      : type == typeInfo
                      ? Colors.black
                      : Colors.white,
                ),
              ),
              const SizedBox(height: 10.0),
              ElevatedButton(
                onPressed: () {
                  scaffoldMessenger.hideCurrentSnackBar();
                  if (!response.isCompleted) {
                    response.complete(true); // User chose to close the SnackBar
                  }
                },
                child: const Text('Close'),
              ),
            ],
          )
        : Text(message),
    action: appCallables.getThemeParams()['closeButtonPlacement'] == "bottom"
        ? null
        : SnackBarAction(
            label: 'Close',
            onPressed: () {
              scaffoldMessenger.hideCurrentSnackBar();
              if (!response.isCompleted) {
                response.complete(true); // User chose to close the SnackBar
              }
            },
          ),
  );
  ScaffoldMessenger.of(context).showSnackBar(snackBar);
  return response.future;
}