2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-27 21:16:48 +00:00
inventree-app/lib/widget/snacks.dart
Oliver d990508237
Some checks failed
Android / build (push) Has been cancelled
CI / test (push) Has been cancelled
iOS / build (push) Has been cancelled
Update Requirements (#541)
* Update package requiremenst

* github workflow updates

* ios build updates

* Theme adjustments

* Further updates

* Fix typo

* Deprecated imperative apply of Flutter's Gradle plugins

Ref: https://docs.flutter.dev/release/breaking-changes/flutter-gradle-plugin-apply

* Refactor wedge scanner

* Add context checks

* Adjust behaviour if testing

* Further refactoring

* Moar checks

* Logic fix

* Fix for wedge scanner test

* Fix for barcode processing

* Fix

* Yet another fix
2024-10-01 12:25:11 +10:00

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 ? 1 : 2),
)
);
}