mirror of
https://github.com/inventree/inventree-app.git
synced 2025-08-25 13:25:52 +00:00
.github
android
assets
ios
lib
barcode
generated
inventree
l10n
settings
widget
company
order
part
stock
attachment_widget.dart
back.dart
dialogs.dart
drawer.dart
fields.dart
home.dart
notes_widget.dart
notifications.dart
paginator.dart
progress.dart
refreshable_state.dart
search.dart
snacks.dart
spinner.dart
api.dart
api_form.dart
app_colors.dart
dsn.dart
helpers.dart
l10.dart
labels.dart
main.dart
preferences.dart
user_profile.dart
res
test
.gitignore
.gitmodules
.metadata
BUILDING.md
LICENSE
README.md
analysis_options.yaml
crowdin.yml
find_dart_files.py
l10n.yaml
pubspec.lock
pubspec.yaml
requirements.txt
tasks.py
79 lines
1.9 KiB
Dart
79 lines
1.9 KiB
Dart
import "package:flutter/material.dart";
|
|
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
|
import "package:one_context/one_context.dart";
|
|
|
|
import "package:inventree/helpers.dart";
|
|
import "package:inventree/l10.dart";
|
|
|
|
/*
|
|
* Display a configurable 'snackbar' at the bottom of the screen
|
|
*/
|
|
void showSnackIcon(String text, {IconData? icon, Function()? onAction, bool? success, String? actionText}) {
|
|
|
|
debug("showSnackIcon: '${text}'");
|
|
|
|
// Escape quickly if we do not have context
|
|
if (!hasContext()) {
|
|
// Debug message for unit testing
|
|
return;
|
|
}
|
|
|
|
BuildContext? context = OneContext().context;
|
|
|
|
if (context != null) {
|
|
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
|
}
|
|
|
|
Color backgroundColor = Colors.deepOrange;
|
|
|
|
// Make some selections based on the "success" value
|
|
if (success != null && success == true) {
|
|
backgroundColor = Colors.lightGreen;
|
|
|
|
// Select an icon if we do not have an action
|
|
if (icon == null && onAction == null) {
|
|
icon = TablerIcons.circle_check;
|
|
}
|
|
|
|
} else if (success != null && success == false) {
|
|
backgroundColor = Colors.deepOrange;
|
|
|
|
if (icon == null && onAction == null) {
|
|
icon = TablerIcons.exclamation_circle;
|
|
}
|
|
}
|
|
|
|
String _action = actionText ?? L10().details;
|
|
|
|
List<Widget> childs = [
|
|
Text(text),
|
|
Spacer(),
|
|
];
|
|
|
|
if (icon != null) {
|
|
childs.add(Icon(icon));
|
|
}
|
|
|
|
OneContext().showSnackBar(builder: (context) => SnackBar(
|
|
content: GestureDetector(
|
|
child: Row(
|
|
children: childs
|
|
),
|
|
onTap: () {
|
|
ScaffoldMessenger.of(context!).hideCurrentSnackBar();
|
|
},
|
|
),
|
|
backgroundColor: backgroundColor,
|
|
action: onAction == null ? null : SnackBarAction(
|
|
label: _action,
|
|
onPressed: () {
|
|
// Immediately dismiss the notification
|
|
ScaffoldMessenger.of(context!).hideCurrentSnackBar();
|
|
onAction();
|
|
}
|
|
),
|
|
duration: Duration(seconds: onAction == null ? 5 : 10),
|
|
)
|
|
);
|
|
|
|
} |