actions-test/lib/tools/snackbar.dart
Jakob Meier 5d333522a5
Simplified network requests & snackbars
and rewrote the component's network requests.

showSimpleSnackbar, allows displaying a simple snackbar,
with text and one action button, that can be clicked.

doNetworkRequest is supposed to be a wrapper for the
already existing post* functions.
It aims to make network requests and error handling easier,
by containing all the try&catch blocks
and being able to show snackbars.
2023-03-24 13:25:34 +01:00

21 lines
526 B
Dart

import 'package:flutter/material.dart';
void showSimpleSnackbar(ScaffoldMessengerState scaffMgr,
{required String text, required String action, Function? onTap}) {
final snackBar = SnackBar(
behavior: SnackBarBehavior.floating,
content: Text(text),
action: SnackBarAction(
label: action,
onPressed: () {
scaffMgr.hideCurrentSnackBar();
if (onTap != null) {
onTap();
}
},
),
);
scaffMgr.hideCurrentSnackBar();
scaffMgr.showSnackBar(snackBar);
}