2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-12-03 18:59:50 +00:00
Files
inventree-app/lib/widget/snacks.dart
Oliver 13d95dd1b1 Modern Label printing (#724)
* Basic widget

* Redirect label printing action

* Refactor label printing code

* Construct form elements

* Refactor to allow re-use of forms

* Basic rendering of label printing form

* Remove dead code

* Pass custom handler through to form context

* Refactoring API forms:

- Allow custom pk field name
- Add callback when values change

* linting

* Dynamically rebuild form

* Handle nested fields

* Handle label printing status

* Run dart format

* Update release notes

* Remove unused var

* Enable close icon

* Handle initial plugin default value

* Store default values:

- Selected template (per label type)
- Selected printing plugin

* Dart format

* Fix dart linting

* use setter

* Just use a public field
2025-11-22 07:26:37 +11:00

82 lines
2.1 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,
showCloseIcon: true,
action: onAction == null
? null
: SnackBarAction(
label: _action,
onPressed: () {
// Immediately dismiss the notification
ScaffoldMessenger.of(context!).hideCurrentSnackBar();
onAction();
},
),
duration: Duration(seconds: onAction == null ? 5 : 10),
),
);
}