mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 13:36:50 +00:00
Simplify PartCategory display
- Pass an InvenTreePartCategory object
This commit is contained in:
parent
5d8126d6d1
commit
d3415e5ebe
@ -6,29 +6,25 @@ import 'package:flutter/material.dart';
|
|||||||
|
|
||||||
class CategoryDisplayWidget extends StatefulWidget {
|
class CategoryDisplayWidget extends StatefulWidget {
|
||||||
|
|
||||||
CategoryDisplayWidget(int catId, {this.category, Key key}) : categoryId = catId, super(key: key);
|
CategoryDisplayWidget(this.category, {Key key}) : super(key: key);
|
||||||
|
|
||||||
InvenTreePartCategory category = null;
|
final InvenTreePartCategory category;
|
||||||
|
|
||||||
final String title = "Category";
|
final String title = "Category";
|
||||||
|
|
||||||
final int categoryId;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_CategoryDisplayState createState() => _CategoryDisplayState(categoryId, category: category);
|
_CategoryDisplayState createState() => _CategoryDisplayState(category);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class _CategoryDisplayState extends State<CategoryDisplayWidget> {
|
class _CategoryDisplayState extends State<CategoryDisplayWidget> {
|
||||||
|
|
||||||
_CategoryDisplayState(int id, {this.category}) : categoryId = id {
|
_CategoryDisplayState(this.category) {
|
||||||
_requestData();
|
_requestData();
|
||||||
}
|
}
|
||||||
|
|
||||||
final int categoryId;
|
|
||||||
|
|
||||||
// The local InvenTreePartCategory object
|
// The local InvenTreePartCategory object
|
||||||
InvenTreePartCategory category = null;
|
final InvenTreePartCategory category;
|
||||||
|
|
||||||
List<InvenTreePartCategory> _subcategories = List<InvenTreePartCategory>();
|
List<InvenTreePartCategory> _subcategories = List<InvenTreePartCategory>();
|
||||||
|
|
||||||
@ -48,11 +44,11 @@ class _CategoryDisplayState extends State<CategoryDisplayWidget> {
|
|||||||
*/
|
*/
|
||||||
void _requestData() {
|
void _requestData() {
|
||||||
|
|
||||||
// Request a list of sub-categories under this one
|
int pk = category?.pk ?? -1;
|
||||||
InvenTreePartCategory().list(filters: {"parent": "$categoryId"}).then((var cats) {
|
|
||||||
_subcategories.clear();
|
|
||||||
|
|
||||||
print("Returned categories: ${cats.length}");
|
// Request a list of sub-categories under this one
|
||||||
|
InvenTreePartCategory().list(filters: {"parent": "$pk"}).then((var cats) {
|
||||||
|
_subcategories.clear();
|
||||||
|
|
||||||
for (var cat in cats) {
|
for (var cat in cats) {
|
||||||
if (cat is InvenTreePartCategory) {
|
if (cat is InvenTreePartCategory) {
|
||||||
@ -65,15 +61,12 @@ class _CategoryDisplayState extends State<CategoryDisplayWidget> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Request a list of parts under this category
|
// Request a list of parts under this category
|
||||||
InvenTreePart().list(filters: {"category": "$categoryId"}).then((var parts) {
|
InvenTreePart().list(filters: {"category": "$pk"}).then((var parts) {
|
||||||
_parts.clear();
|
_parts.clear();
|
||||||
|
|
||||||
print("Returned parts: ${parts.length}");
|
|
||||||
|
|
||||||
for (var part in parts) {
|
for (var part in parts) {
|
||||||
if (part is InvenTreePart) {
|
if (part is InvenTreePart) {
|
||||||
_parts.add(part);
|
_parts.add(part);
|
||||||
print("Adding part: ${part.name}");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,11 +86,11 @@ class _CategoryDisplayState extends State<CategoryDisplayWidget> {
|
|||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Text(
|
Text(
|
||||||
"Subcategories",
|
"Subcategories - ${_subcategories.length}",
|
||||||
),
|
),
|
||||||
Expanded(child: SubcategoryList(_subcategories)),
|
Expanded(child: SubcategoryList(_subcategories)),
|
||||||
Divider(),
|
Divider(),
|
||||||
Text("Parts"),
|
Text("Parts - ${_parts.length}"),
|
||||||
Expanded(child: PartList(_parts)),
|
Expanded(child: PartList(_parts)),
|
||||||
Spacer(),
|
Spacer(),
|
||||||
]
|
]
|
||||||
@ -123,7 +116,7 @@ class SubcategoryList extends StatelessWidget {
|
|||||||
if (cat is InvenTreePartCategory) {
|
if (cat is InvenTreePartCategory) {
|
||||||
print("Found cat: <${cat.pk}> : ${cat.name} - ${cat.description}");
|
print("Found cat: <${cat.pk}> : ${cat.name} - ${cat.description}");
|
||||||
|
|
||||||
Navigator.push(context, MaterialPageRoute(builder: (context) => CategoryDisplayWidget(pk, category: cat)));
|
Navigator.push(context, MaterialPageRoute(builder: (context) => CategoryDisplayWidget(cat)));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user