2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-06-12 18:25:26 +00:00

snack bar now uses OneContext()

This commit is contained in:
Oliver Walters
2021-02-16 23:24:23 +11:00
parent 33483eb9e1
commit 8ae4d2b584
5 changed files with 72 additions and 23 deletions

View File

@ -11,26 +11,44 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:one_context/one_context.dart';
void showSnackIcon(GlobalKey<ScaffoldState> key, String text, {IconData icon, bool success}) {
void showSnackIcon(String text, {IconData icon, Function onTap, bool success}) {
// Hide the current snackbar
key.currentState.hideCurrentSnackBar();
OneContext().hideCurrentSnackBar();
Color backgroundColor;
// Make some selections based on the "success" value
if (success == true) {
backgroundColor = Colors.lightGreen;
// Unspecified icon?
if (icon == null) {
icon = FontAwesomeIcons.checkCircle;
}
} else if (success == false) {
backgroundColor = Colors.deepOrange;
if (icon == null) {
icon = FontAwesomeIcons.timesCircle;
}
// If icon not specified, use the success status
if (icon == null) {
icon = (success == false) ? FontAwesomeIcons.timesCircle : FontAwesomeIcons.checkCircle;
}
key.currentState.showSnackBar(
SnackBar(
content: Row(
OneContext().showSnackBar(builder: (context) => SnackBar(
content: GestureDetector(
child: Row(
children: [
Text(text),
Spacer(),
FaIcon(icon)
]
],
),
)
);
onTap: onTap,
),
backgroundColor: backgroundColor,
));
}