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

@ -1,4 +1,3 @@
import "dart:io";
import "package:flutter/material.dart";
@ -17,7 +16,6 @@ import "package:inventree/widget/progress.dart";
import "package:inventree/widget/snacks.dart";
import "package:inventree/widget/refreshable_state.dart";
/*
* A generic widget for displaying a list of attachments.
*
@ -25,8 +23,12 @@ import "package:inventree/widget/refreshable_state.dart";
* we pass a subclassed instance of the InvenTreeAttachment model.
*/
class AttachmentWidget extends StatefulWidget {
const AttachmentWidget(this.attachmentClass, this.modelId, this.imagePrefix, this.hasUploadPermission) : super();
const AttachmentWidget(
this.attachmentClass,
this.modelId,
this.imagePrefix,
this.hasUploadPermission,
) : super();
final InvenTreeAttachment attachmentClass;
final int modelId;
@ -37,9 +39,7 @@ class AttachmentWidget extends StatefulWidget {
_AttachmentWidgetState createState() => _AttachmentWidgetState();
}
class _AttachmentWidgetState extends RefreshableState<AttachmentWidget> {
_AttachmentWidgetState();
List<InvenTreeAttachment> attachments = [];
@ -64,7 +64,7 @@ class _AttachmentWidgetState extends RefreshableState<AttachmentWidget> {
refresh(context);
});
});
}
},
),
IconButton(
icon: Icon(TablerIcons.file_upload),
@ -74,20 +74,19 @@ class _AttachmentWidgetState extends RefreshableState<AttachmentWidget> {
refresh(context);
});
});
}
)
},
),
];
}
Future<void> upload(BuildContext context, File? file) async {
if (file == null) return;
showLoadingOverlay();
final bool result = await widget.attachmentClass.uploadAttachment(
file,
widget.modelId
file,
widget.modelId,
);
hideLoadingOverlay();
@ -101,35 +100,39 @@ class _AttachmentWidgetState extends RefreshableState<AttachmentWidget> {
refresh(context);
}
Future<void> editAttachment(BuildContext context, InvenTreeAttachment attachment) async
{
attachment.editForm(context, L10().editAttachment).then((result) => {
refresh(context)
});
Future<void> editAttachment(
BuildContext context,
InvenTreeAttachment attachment,
) async {
attachment
.editForm(context, L10().editAttachment)
.then((result) => {refresh(context)});
}
/*
* Delete the specified attachment
*/
Future<void> deleteAttachment(BuildContext context, InvenTreeAttachment attachment) async {
Future<void> deleteAttachment(
BuildContext context,
InvenTreeAttachment attachment,
) async {
final bool result = await attachment.delete();
showSnackIcon(
result ? L10().deleteSuccess : L10().deleteFailed,
success: result
success: result,
);
refresh(context);
}
/*
* Display an option context menu for the selected attachment
*/
Future<void> showOptionsMenu(BuildContext context, InvenTreeAttachment attachment) async {
Future<void> showOptionsMenu(
BuildContext context,
InvenTreeAttachment attachment,
) async {
OneContext().showDialog(
builder: (BuildContext ctx) {
return SimpleDialog(
@ -144,7 +147,7 @@ class _AttachmentWidgetState extends RefreshableState<AttachmentWidget> {
child: ListTile(
title: Text(L10().edit),
leading: Icon(TablerIcons.edit),
)
),
),
SimpleDialogOption(
onPressed: () async {
@ -154,29 +157,27 @@ class _AttachmentWidgetState extends RefreshableState<AttachmentWidget> {
child: ListTile(
title: Text(L10().delete),
leading: Icon(TablerIcons.trash, color: COLOR_DANGER),
)
)
]
),
),
],
);
}
},
);
}
@override
Future<void> request(BuildContext context) async {
Map<String, String> filters = {};
if (InvenTreeAPI().supportsModernAttachments) {
filters["model_type"] = widget.attachmentClass.REF_MODEL_TYPE;
filters["model_id"] = widget.modelId.toString();
} else {
filters[widget.attachmentClass.REFERENCE_FIELD] = widget.modelId.toString();
filters[widget.attachmentClass.REFERENCE_FIELD] = widget.modelId
.toString();
}
await widget.attachmentClass.list(
filters: filters
).then((var results) {
await widget.attachmentClass.list(filters: filters).then((var results) {
attachments.clear();
for (var result in results) {
@ -186,57 +187,58 @@ class _AttachmentWidgetState extends RefreshableState<AttachmentWidget> {
}
});
setState(() {
});
setState(() {});
}
@override
List<Widget> getTiles(BuildContext context) {
List<Widget> tiles = [];
// An "attachment" can either be a file, or a URL
for (var attachment in attachments) {
if (attachment.filename.isNotEmpty) {
tiles.add(ListTile(
title: Text(attachment.filename),
subtitle: Text(attachment.comment),
leading: Icon(attachment.icon, color: COLOR_ACTION),
onTap: () async {
showLoadingOverlay();
await attachment.downloadAttachment();
hideLoadingOverlay();
},
onLongPress: () {
showOptionsMenu(context, attachment);
},
));
}
else if (attachment.link.isNotEmpty) {
tiles.add(ListTile(
title: Text(attachment.link),
subtitle: Text(attachment.comment),
leading: Icon(TablerIcons.link, color: COLOR_ACTION),
onTap: () async {
var uri = Uri.tryParse(attachment.link.trimLeft());
if (uri != null && await canLaunchUrl(uri)) {
await launchUrl(uri);
}
},
onLongPress: () {
showOptionsMenu(context, attachment);
},
));
tiles.add(
ListTile(
title: Text(attachment.filename),
subtitle: Text(attachment.comment),
leading: Icon(attachment.icon, color: COLOR_ACTION),
onTap: () async {
showLoadingOverlay();
await attachment.downloadAttachment();
hideLoadingOverlay();
},
onLongPress: () {
showOptionsMenu(context, attachment);
},
),
);
} else if (attachment.link.isNotEmpty) {
tiles.add(
ListTile(
title: Text(attachment.link),
subtitle: Text(attachment.comment),
leading: Icon(TablerIcons.link, color: COLOR_ACTION),
onTap: () async {
var uri = Uri.tryParse(attachment.link.trimLeft());
if (uri != null && await canLaunchUrl(uri)) {
await launchUrl(uri);
}
},
onLongPress: () {
showOptionsMenu(context, attachment);
},
),
);
}
}
if (tiles.isEmpty) {
tiles.add(ListTile(
leading: Icon(TablerIcons.file_x, color: COLOR_WARNING),
title: Text(L10().attachmentNone),
));
tiles.add(
ListTile(
leading: Icon(TablerIcons.file_x, color: COLOR_WARNING),
title: Text(L10().attachmentNone),
),
);
}
return tiles;