diff --git a/lib/inventree/part.dart b/lib/inventree/part.dart index 61381920..255f9cb2 100644 --- a/lib/inventree/part.dart +++ b/lib/inventree/part.dart @@ -132,6 +132,14 @@ class InvenTreePart extends InvenTreeModel { @override String URL = "part/"; + @override + Map defaultListFilters() { + return { + "cascade": "false", + "active": "true", + }; + } + @override Map defaultGetFilters() { return { @@ -202,11 +210,20 @@ class InvenTreePart extends InvenTreeModel { int get categoryId => jsondata['category'] as int ?? null; // Get the category name for the Part instance - String get categoryName => jsondata['category_detail']['name'] as String ?? ''; + String get categoryName { + if (categoryId == null) return ''; + if (!jsondata.containsKey('category_detail')) return ''; + + return jsondata['category_detail']['name'] as String ?? ''; + } // Get the category description for the Part instance - String get categoryDescription => jsondata['category_detail']['description'] as String ?? ''; + String get categoryDescription { + if (categoryId == null) return ''; + if (!jsondata.containsKey('category_detail')) return ''; + return jsondata['category_detail']['description'] as String ?? ''; + } // Get the image URL for the Part instance String get _image => jsondata['image'] ?? ''; diff --git a/lib/widget/part_detail.dart b/lib/widget/part_detail.dart index 5dec0c19..9d800978 100644 --- a/lib/widget/part_detail.dart +++ b/lib/widget/part_detail.dart @@ -136,7 +136,7 @@ class _PartDisplayState extends RefreshableState { ListTile( title: Text("Part Category"), subtitle: Text("${part.categoryName}"), - leading: FaIcon(FontAwesomeIcons.stream), + leading: FaIcon(FontAwesomeIcons.sitemap), onTap: () { if (part.categoryId > 0) { InvenTreePartCategory().get(context, part.categoryId).then((var cat) { @@ -151,8 +151,11 @@ class _PartDisplayState extends RefreshableState { tiles.add( ListTile( title: Text("Part Category"), - subtitle: Text("No category set"), - leading: FaIcon(FontAwesomeIcons.stream), + subtitle: Text("Top level part category"), + leading: FaIcon(FontAwesomeIcons.sitemap), + onTap: () { + Navigator.push(context, MaterialPageRoute(builder: (context) => CategoryDisplayWidget(null))); + }, ) ); }