mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-12 18:25:26 +00:00
API error messages now use snackIcon
- Press "details" for further error information - Is nice
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
|
||||
import 'package:InvenTree/widget/snacks.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
@ -86,61 +87,64 @@ Future<void> showInfoDialog(BuildContext context, String title, String descripti
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> showErrorDialog(BuildContext context, String title, String description, {IconData icon = FontAwesomeIcons.exclamationCircle, String error, Function onDismissed}) async {
|
||||
Future<void> showErrorDialog(String title, String description, {IconData icon = FontAwesomeIcons.exclamationCircle, String error, Function onDismissed}) async {
|
||||
|
||||
if (error == null || error.isEmpty) {
|
||||
error = I18N.of(context).error;
|
||||
error = I18N.of(OneContext().context).error;
|
||||
}
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (dialogContext) {
|
||||
return SimpleDialog(
|
||||
title: ListTile(
|
||||
title: Text(error),
|
||||
leading: FaIcon(icon),
|
||||
),
|
||||
children: <Widget>[
|
||||
ListTile(
|
||||
title: Text(title),
|
||||
subtitle: Text(description)
|
||||
)
|
||||
]
|
||||
);
|
||||
}).then((value) {
|
||||
if (onDismissed != null) {
|
||||
onDismissed();
|
||||
}
|
||||
});
|
||||
OneContext().showDialog(
|
||||
builder: (context) => SimpleDialog(
|
||||
title: ListTile(
|
||||
title: Text(error),
|
||||
leading: FaIcon(icon),
|
||||
),
|
||||
children: [
|
||||
ListTile(
|
||||
title: Text(title),
|
||||
subtitle: Text(description),
|
||||
)
|
||||
],
|
||||
)
|
||||
).then((value) {
|
||||
if (onDismissed != null) {
|
||||
onDismissed();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> showServerError(BuildContext context, String title, String description) async {
|
||||
Future<void> showServerError(String title, String description) async {
|
||||
|
||||
if (title == null || title.isEmpty) {
|
||||
title = I18N.of(context).serverError;
|
||||
title = I18N.of(OneContext().context).serverError;
|
||||
}
|
||||
|
||||
await showErrorDialog(
|
||||
context,
|
||||
title,
|
||||
description,
|
||||
error: I18N.of(context).serverError,
|
||||
icon: FontAwesomeIcons.server
|
||||
showSnackIcon(
|
||||
title,
|
||||
success: false,
|
||||
actionText: I18N.of(OneContext().context).details,
|
||||
onAction: () {
|
||||
showErrorDialog(
|
||||
title,
|
||||
description,
|
||||
error: I18N.of(OneContext().context).serverError,
|
||||
icon: FontAwesomeIcons.server
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> showStatusCodeError(BuildContext context, int status, {int expected = 200}) async {
|
||||
Future<void> showStatusCodeError(int status, {int expected = 200}) async {
|
||||
|
||||
await showServerError(
|
||||
context,
|
||||
"Invalid Response Code",
|
||||
showServerError(
|
||||
I18N.of(OneContext().context).responseInvalid,
|
||||
"Server responded with status code ${status}"
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> showTimeoutError(BuildContext context) async {
|
||||
|
||||
await showServerError(context, I18N.of(context).timeout, I18N.of(context).noResponse);
|
||||
await showServerError(I18N.of(context).timeout, I18N.of(context).noResponse);
|
||||
}
|
||||
|
||||
void showProgressDialog(BuildContext context, String title, String description) {
|
||||
|
@ -13,7 +13,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:one_context/one_context.dart';
|
||||
|
||||
void showSnackIcon(String text, {IconData icon, Function onTap, bool success}) {
|
||||
void showSnackIcon(String text, {IconData icon, Function onAction, bool success, String actionText}) {
|
||||
|
||||
OneContext().hideCurrentSnackBar();
|
||||
|
||||
@ -23,32 +23,35 @@ void showSnackIcon(String text, {IconData icon, Function onTap, bool success}) {
|
||||
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;
|
||||
}
|
||||
SnackBarAction action;
|
||||
|
||||
if (onAction != null && actionText != null) {
|
||||
action = SnackBarAction(
|
||||
label: actionText,
|
||||
onPressed: onAction,
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> childs = [
|
||||
Text(text),
|
||||
Spacer(),
|
||||
];
|
||||
|
||||
if (icon != null) {
|
||||
childs.add(FaIcon(icon));
|
||||
}
|
||||
|
||||
OneContext().showSnackBar(builder: (context) => SnackBar(
|
||||
content: GestureDetector(
|
||||
child: Row(
|
||||
children: [
|
||||
Text(text),
|
||||
Spacer(),
|
||||
FaIcon(icon)
|
||||
],
|
||||
),
|
||||
onTap: onTap,
|
||||
content: Row(
|
||||
children: childs
|
||||
),
|
||||
backgroundColor: backgroundColor,
|
||||
));
|
||||
action: action
|
||||
)
|
||||
);
|
||||
|
||||
}
|
Reference in New Issue
Block a user