mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-16 12:15:31 +00:00
Change from fontawesome to tabler icons (#516)
* Change from fontawesome to tabler icons - Consistent with the frontend * Cleanup conflicts * Use double quotes * remove unused import * Update release notes * Migrate some google icons to tabler icons * Icon update * Properly support display of custom icons * Fix lookup
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
import "dart:async";
|
||||
import "dart:io";
|
||||
|
||||
import "package:font_awesome_flutter/font_awesome_flutter.dart";
|
||||
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
||||
import "package:flutter/material.dart";
|
||||
import "package:inventree/widget/snacks.dart";
|
||||
import "package:url_launcher/url_launcher.dart";
|
||||
@ -9,7 +9,6 @@ import "package:path/path.dart" as path;
|
||||
|
||||
import "package:inventree/api.dart";
|
||||
import "package:inventree/api_form.dart";
|
||||
import "package:inventree/fa_icon_mapping.dart";
|
||||
import "package:inventree/l10.dart";
|
||||
import "package:inventree/helpers.dart";
|
||||
import "package:inventree/inventree/sentry.dart";
|
||||
@ -309,49 +308,31 @@ class InvenTreeModel {
|
||||
* - Second part specifies the icon
|
||||
*
|
||||
*/
|
||||
FaIcon? get customIcon {
|
||||
String icon = (jsondata["icon"] ?? "").toString();
|
||||
IconData? get customIcon {
|
||||
String icon = (jsondata["icon"] ?? "").toString().trim();
|
||||
|
||||
// Empty icon (default)
|
||||
if (icon.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final split = icon.trim().split(" ");
|
||||
|
||||
// Must have two distinct units
|
||||
if (split.length != 2) {
|
||||
// Tabler icon is of the format "ti:<icon>:<style"
|
||||
if (!icon.startsWith("ti:")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String style = split[0];
|
||||
String name = split[1];
|
||||
List<String> items = icon.split(":");
|
||||
|
||||
// Remove "fa-" leading text (if provided)
|
||||
if (name.startsWith("fa-")) {
|
||||
name = name.substring(3);
|
||||
}
|
||||
|
||||
int iconHex = fontAwesomeIconMap[name] ?? 0;
|
||||
|
||||
// No match for the icon name
|
||||
if (iconHex == 0) {
|
||||
if (items.length < 2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
switch (style) {
|
||||
case "fas":
|
||||
return FaIcon(IconDataSolid(iconHex));
|
||||
case "fab":
|
||||
return FaIcon(IconDataBrands(iconHex));
|
||||
case "fa":
|
||||
return FaIcon(IconDataRegular(iconHex));
|
||||
case "fal":
|
||||
return FaIcon(IconDataLight(iconHex));
|
||||
default:
|
||||
// No match
|
||||
return null;
|
||||
}
|
||||
String key = items[1];
|
||||
|
||||
key = key.replaceAll("-", "_");
|
||||
|
||||
// Tabler icon lookup
|
||||
return TablerIcons.all[key];
|
||||
}
|
||||
|
||||
/* Extract any custom barcode data available for the model.
|
||||
@ -960,13 +941,13 @@ class InvenTreeAttachment extends InvenTreeModel {
|
||||
String fn = filename.toLowerCase();
|
||||
|
||||
if (fn.endsWith(".pdf")) {
|
||||
return FontAwesomeIcons.filePdf;
|
||||
return TablerIcons.file_type_pdf;
|
||||
} else if (fn.endsWith(".csv")) {
|
||||
return FontAwesomeIcons.fileCsv;
|
||||
return TablerIcons.file_type_csv;
|
||||
} else if (fn.endsWith(".doc") || fn.endsWith(".docx")) {
|
||||
return FontAwesomeIcons.fileWord;
|
||||
return TablerIcons.file_type_doc;
|
||||
} else if (fn.endsWith(".xls") || fn.endsWith(".xlsx")) {
|
||||
return FontAwesomeIcons.fileExcel;
|
||||
return TablerIcons.file_type_xls;
|
||||
}
|
||||
|
||||
// Image formats
|
||||
@ -980,11 +961,11 @@ class InvenTreeAttachment extends InvenTreeModel {
|
||||
|
||||
for (String fmt in img_formats) {
|
||||
if (fn.endsWith(fmt)) {
|
||||
return FontAwesomeIcons.fileImage;
|
||||
return TablerIcons.file_type_jpg;
|
||||
}
|
||||
}
|
||||
|
||||
return FontAwesomeIcons.fileLines;
|
||||
return TablerIcons.file;
|
||||
}
|
||||
|
||||
String get comment => getString("comment");
|
||||
|
Reference in New Issue
Block a user