2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-07-01 11:20:41 +00:00

Format Code and Add Format Checks to CI (#643)

* Remove unused lib/generated/i18n.dart

* Use `fvm dart format .`

* Add contributing guidelines

* Enforce dart format

* Add `dart format off` directive to generated files
This commit is contained in:
Ben Hagen
2025-06-24 01:55:01 +02:00
committed by GitHub
parent e9db6532e4
commit 4444884afa
100 changed files with 5332 additions and 5592 deletions

View File

@ -9,12 +9,14 @@ import "package:inventree/l10.dart";
import "package:inventree/preferences.dart";
import "package:inventree/widget/snacks.dart";
/*
* Launch a dialog allowing the user to select from a list of options
*/
Future<void> choiceDialog(String title, List<Widget> items, {Function? onSelected}) async {
Future<void> choiceDialog(
String title,
List<Widget> items, {
Function? onSelected,
}) async {
List<Widget> choices = [];
for (int idx = 0; idx < items.length; idx++) {
@ -27,7 +29,7 @@ Future<void> choiceDialog(String title, List<Widget> items, {Function? onSelecte
onSelected(idx);
}
},
)
),
);
}
@ -39,31 +41,33 @@ Future<void> choiceDialog(String title, List<Widget> items, {Function? onSelecte
builder: (BuildContext context) {
return AlertDialog(
title: Text(title),
content: SingleChildScrollView(
child: Column(
children: choices,
)
),
content: SingleChildScrollView(child: Column(children: choices)),
actions: [
TextButton(
child: Text(L10().cancel),
onPressed: () {
Navigator.pop(context);
},
)
),
],
);
}
},
);
}
/*
* Display a "confirmation" dialog allowing the user to accept or reject an action
*/
Future<void> confirmationDialog(String title, String text, {Color? color, IconData icon = TablerIcons.help_circle, String? acceptText, String? rejectText, Function? onAccept, Function? onReject}) async {
Future<void> confirmationDialog(
String title,
String text, {
Color? color,
IconData icon = TablerIcons.help_circle,
String? acceptText,
String? rejectText,
Function? onAccept,
Function? onReject,
}) async {
String _accept = acceptText ?? L10().ok;
String _reject = rejectText ?? L10().cancel;
@ -90,7 +94,7 @@ Future<void> confirmationDialog(String title, String text, {Color? color, IconDa
if (onReject != null) {
onReject();
}
}
},
),
TextButton(
child: Text(_accept),
@ -102,14 +106,13 @@ Future<void> confirmationDialog(String title, String text, {Color? color, IconDa
onAccept();
}
},
)
]
),
],
);
}
},
);
}
/*
* Construct an error dialog showing information to the user
*
@ -117,24 +120,23 @@ Future<void> confirmationDialog(String title, String text, {Color? color, IconDa
* @description = Simple string description of error
* @data = Error response (e.g from server)
*/
Future<void> showErrorDialog(String title, {String description = "", APIResponse? response, IconData icon = TablerIcons.exclamation_circle, Function? onDismissed}) async {
Future<void> showErrorDialog(
String title, {
String description = "",
APIResponse? response,
IconData icon = TablerIcons.exclamation_circle,
Function? onDismissed,
}) async {
List<Widget> children = [];
if (description.isNotEmpty) {
children.add(
ListTile(
title: Text(description),
)
);
children.add(ListTile(title: Text(description)));
} else if (response != null) {
// Look for extra error information in the provided APIResponse object
switch (response.statusCode) {
case 400: // Bad request (typically bad input)
case 400: // Bad request (typically bad input)
if (response.data is Map<String, dynamic>) {
for (String field in response.asMap().keys) {
dynamic error = response.data[field];
if (error is List) {
@ -143,15 +145,15 @@ Future<void> showErrorDialog(String title, {String description = "", APIResponse
ListTile(
title: Text(field),
subtitle: Text(error[ii].toString()),
)
),
);
}
} else {
children.add(
ListTile(
title: Text(field),
subtitle: Text(response.data[field].toString()),
)
ListTile(
title: Text(field),
subtitle: Text(response.data[field].toString()),
),
);
}
}
@ -159,8 +161,8 @@ Future<void> showErrorDialog(String title, {String description = "", APIResponse
children.add(
ListTile(
title: Text(L10().responseInvalid),
subtitle: Text(response.data.toString())
)
subtitle: Text(response.data.toString()),
),
);
}
default:
@ -169,16 +171,15 @@ Future<void> showErrorDialog(String title, {String description = "", APIResponse
ListTile(
title: Text(L10().statusCode),
subtitle: Text(response.statusCode.toString()),
)
),
);
children.add(
ListTile(
title: Text(L10().responseData),
subtitle: Text(response.data.toString()),
)
),
);
}
}
@ -186,26 +187,28 @@ Future<void> showErrorDialog(String title, {String description = "", APIResponse
return;
}
OneContext().showDialog(
builder: (context) => SimpleDialog(
title: ListTile(
title: Text(title),
leading: Icon(icon),
),
children: children
)
).then((value) {
if (onDismissed != null) {
onDismissed();
}
});
OneContext()
.showDialog(
builder: (context) => SimpleDialog(
title: ListTile(title: Text(title), leading: Icon(icon)),
children: children,
),
)
.then((value) {
if (onDismissed != null) {
onDismissed();
}
});
}
/*
* Display a message indicating the nature of a server / API error
*/
Future<void> showServerError(String url, String title, String description) async {
Future<void> showServerError(
String url,
String title,
String description,
) async {
if (!hasContext()) {
return;
}
@ -220,7 +223,9 @@ Future<void> showServerError(String url, String title, String description) async
}
// Play a sound
final bool tones = await InvenTreeSettingsManager().getValue(INV_SOUNDS_SERVER, true) as bool;
final bool tones =
await InvenTreeSettingsManager().getValue(INV_SOUNDS_SERVER, true)
as bool;
if (tones) {
playAudioFile("sounds/server_error.mp3");
@ -234,19 +239,22 @@ Future<void> showServerError(String url, String title, String description) async
actionText: L10().details,
onAction: () {
showErrorDialog(
title,
description: description,
icon: TablerIcons.server
title,
description: description,
icon: TablerIcons.server,
);
}
},
);
}
/*
* Displays an error indicating that the server returned an unexpected status code
*/
Future<void> showStatusCodeError(String url, int status, {String details=""}) async {
Future<void> showStatusCodeError(
String url,
int status, {
String details = "",
}) async {
String msg = statusCodeToString(status);
String extra = url + "\n" + "${L10().statusCode}: ${status}";
@ -255,14 +263,9 @@ Future<void> showStatusCodeError(String url, int status, {String details=""}) as
extra += details;
}
showServerError(
url,
msg,
extra,
);
showServerError(url, msg, extra);
}
/*
* Provide a human-readable descriptor for a particular error code
*/
@ -297,7 +300,6 @@ String statusCodeToString(int status) {
}
}
/*
* Displays a message indicating that the server timed out on a certain request
*/