mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-13 18:55:34 +00:00
Capture context data in the LocationDisplay widget
This commit is contained in:
@ -56,7 +56,7 @@ class _CategoryDisplayState extends State<CategoryDisplayWidget> {
|
||||
int pk = category?.pk ?? -1;
|
||||
|
||||
// Request a list of sub-categories under this one
|
||||
InvenTreePartCategory().list(filters: {"parent": "$pk"}).then((var cats) {
|
||||
InvenTreePartCategory().list(context, filters: {"parent": "$pk"}).then((var cats) {
|
||||
_subcategories.clear();
|
||||
|
||||
for (var cat in cats) {
|
||||
@ -70,7 +70,7 @@ class _CategoryDisplayState extends State<CategoryDisplayWidget> {
|
||||
});
|
||||
|
||||
// Request a list of parts under this category
|
||||
InvenTreePart().list(filters: {"category": "$pk"}).then((var parts) {
|
||||
InvenTreePart().list(context, filters: {"category": "$pk"}).then((var parts) {
|
||||
_parts.clear();
|
||||
|
||||
for (var part in parts) {
|
||||
|
@ -46,7 +46,7 @@ class _CompanyListState extends State<CompanyListWidget> {
|
||||
|
||||
void _requestData() {
|
||||
|
||||
InvenTreeCompany().list(filters: _filters).then((var companies) {
|
||||
InvenTreeCompany().list(context, filters: _filters).then((var companies) {
|
||||
|
||||
_companies.clear();
|
||||
|
||||
|
@ -22,6 +22,7 @@ void showErrorDialog(BuildContext context, String title, String description) {
|
||||
}
|
||||
|
||||
void showProgressDialog(BuildContext context, String title, String description) {
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
|
@ -10,6 +10,8 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
|
||||
class LocationDisplayWidget extends StatefulWidget {
|
||||
|
||||
|
||||
|
||||
LocationDisplayWidget(this.location, {Key key}) : super(key: key);
|
||||
|
||||
final InvenTreeStockLocation location;
|
||||
@ -23,8 +25,15 @@ class LocationDisplayWidget extends StatefulWidget {
|
||||
|
||||
class _LocationDisplayState extends State<LocationDisplayWidget> {
|
||||
|
||||
BuildContext context;
|
||||
|
||||
_LocationDisplayState(this.location) {
|
||||
_requestData();
|
||||
|
||||
}
|
||||
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) => _requestData(context));
|
||||
}
|
||||
|
||||
final InvenTreeStockLocation location;
|
||||
@ -60,12 +69,14 @@ class _LocationDisplayState extends State<LocationDisplayWidget> {
|
||||
* - List of sublocations under this one
|
||||
* - List of stock items at this location
|
||||
*/
|
||||
void _requestData() {
|
||||
void _requestData(BuildContext context) {
|
||||
|
||||
print("Requesting data!");
|
||||
|
||||
int pk = location?.pk ?? -1;
|
||||
|
||||
// Request a list of sub-locations under this one
|
||||
InvenTreeStockLocation().list(filters: {"parent": "$pk"}).then((var locs) {
|
||||
InvenTreeStockLocation().list(context, filters: {"parent": "$pk"}).then((var locs) {
|
||||
_sublocations.clear();
|
||||
|
||||
for (var loc in locs) {
|
||||
@ -76,18 +87,18 @@ class _LocationDisplayState extends State<LocationDisplayWidget> {
|
||||
|
||||
setState(() {});
|
||||
|
||||
// Request a list of stock-items under this one
|
||||
InvenTreeStockItem().list(filters: {"location": "$pk"}).then((var items) {
|
||||
_items.clear();
|
||||
// Request a list of stock-items under this one
|
||||
InvenTreeStockItem().list(context, filters: {"location": "$pk"}).then((var items) {
|
||||
_items.clear();
|
||||
|
||||
for (var item in items) {
|
||||
if (item is InvenTreeStockItem) {
|
||||
_items.add(item);
|
||||
for (var item in items) {
|
||||
if (item is InvenTreeStockItem) {
|
||||
_items.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setState(() {});
|
||||
});
|
||||
setState(() {});
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
@ -135,6 +146,12 @@ class _LocationDisplayState extends State<LocationDisplayWidget> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
// Save the context
|
||||
this.context = context;
|
||||
|
||||
print("Saved context!");
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(_title),
|
||||
|
Reference in New Issue
Block a user