2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-06-14 11:15:26 +00:00
Files
.github
android
assets
ios
lib
generated
inventree
l10n
settings
widget
back.dart
category_display.dart
category_list.dart
company_detail.dart
company_list.dart
dialogs.dart
drawer.dart
fields.dart
home.dart
location_display.dart
location_list.dart
paginator.dart
part_attachments_widget.dart
part_detail.dart
part_image_widget.dart
part_list.dart
part_notes.dart
part_suppliers.dart
progress.dart
purchase_order_detail.dart
purchase_order_list.dart
refreshable_state.dart
search.dart
snacks.dart
spinner.dart
starred_parts.dart
stock_detail.dart
stock_item_history.dart
stock_item_test_results.dart
stock_list.dart
stock_notes.dart
submit_feedback.dart
api.dart
api_form.dart
app_colors.dart
app_settings.dart
barcode.dart
dummy_dsn.dart
helpers.dart
l10.dart
main.dart
preferences.dart
user_profile.dart
res
test
.gitignore
.gitmodules
.metadata
LICENSE
README.md
RELEASE.md
analysis_options.yaml
l10n.yaml
pubspec.lock
pubspec.yaml
Oliver Walters 2a6df373c5 Refactor imports
2022-03-29 19:54:19 +11:00

73 lines
1.5 KiB
Dart

/*
* Display a snackbar with:
*
* a) Text on the left
* b) Icon on the right
*
* | Text <icon> |
*/
import "package:flutter/material.dart";
import "package:font_awesome_flutter/font_awesome_flutter.dart";
import "package:one_context/one_context.dart";
import "package:inventree/l10.dart";
void showSnackIcon(String text, {IconData? icon, Function()? onAction, bool? success, String? actionText}) {
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 = FontAwesomeIcons.checkCircle;
}
} else if (success != null && success == false) {
backgroundColor = Colors.deepOrange;
if (icon == null && onAction == null) {
icon = FontAwesomeIcons.exclamationCircle;
}
}
String _action = actionText ?? L10().details;
SnackBarAction? action;
if (onAction != null) {
action = SnackBarAction(
label: _action,
onPressed: onAction,
);
}
List<Widget> childs = [
Text(text),
Spacer(),
];
if (icon != null) {
childs.add(FaIcon(icon));
}
OneContext().showSnackBar(builder: (context) => SnackBar(
content: Row(
children: childs
),
backgroundColor: backgroundColor,
action: action
)
);
}