2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-28 05:26:47 +00:00

Capture context data in the LocationDisplay widget

This commit is contained in:
Oliver Walters 2020-04-15 10:33:10 +10:00
parent 5ed13e69aa
commit 3fead77f6d
7 changed files with 42 additions and 56 deletions

View File

@ -201,6 +201,8 @@ class InvenTreeModel {
return null; return null;
} }
hideProgressDialog(context);
// A list of "InvenTreeModel" items // A list of "InvenTreeModel" items
List<InvenTreeModel> results = new List<InvenTreeModel>(); List<InvenTreeModel> results = new List<InvenTreeModel>();

View File

@ -66,7 +66,7 @@ class InvenTreePartCategory extends InvenTreeModel {
class InvenTreePart extends InvenTreeModel { class InvenTreePart extends InvenTreeModel {
@override @override
String Name = "Part"; String NAME = "Part";
@override @override
String URL = "part/"; String URL = "part/";

View File

@ -22,6 +22,8 @@ import 'preferences.dart';
import 'package:InvenTree/inventree/part.dart'; import 'package:InvenTree/inventree/part.dart';
void main() async { void main() async {
// await PrefService.init(prefix: "inventree_"); // await PrefService.init(prefix: "inventree_");
@ -31,10 +33,10 @@ void main() async {
// Load login details // Load login details
InvenTreePreferences().loadLoginDetails(); InvenTreePreferences().loadLoginDetails();
runApp(MyApp()); runApp(InvenTreeApp());
} }
class MyApp extends StatelessWidget { class InvenTreeApp extends StatelessWidget {
// This widget is the root of your application. // This widget is the root of your application.
@override @override
@ -42,16 +44,8 @@ class MyApp extends StatelessWidget {
return MaterialApp( return MaterialApp(
title: 'InvenTree', title: 'InvenTree',
theme: ThemeData( theme: ThemeData(
// This is the theme of your application. primarySwatch: Colors.lightBlue,
// secondaryHeaderColor: Colors.blueGrey,
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.lightGreen,
), ),
home: MyHomePage(title: 'InvenTree'), home: MyHomePage(title: 'InvenTree'),
); );
@ -59,34 +53,6 @@ class MyApp extends StatelessWidget {
} }
class ProductList extends StatelessWidget {
final List<InvenTreePart> _parts;
ProductList(this._parts);
Widget _buildPart(BuildContext context, int index) {
InvenTreePart part;
if (index < _parts.length) {
part = _parts[index];
}
return Card(
child: Column(
children: <Widget>[
Text('${part.name} - ${part.description}'),
]
)
);
}
@override
Widget build(BuildContext context) {
return ListView.builder(itemBuilder: _buildPart, itemCount: _parts.length);
}
}
class MyHomePage extends StatefulWidget { class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key); MyHomePage({Key key, this.title}) : super(key: key);

View File

@ -56,7 +56,7 @@ class _CategoryDisplayState extends State<CategoryDisplayWidget> {
int pk = category?.pk ?? -1; int pk = category?.pk ?? -1;
// Request a list of sub-categories under this one // 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(); _subcategories.clear();
for (var cat in cats) { for (var cat in cats) {
@ -70,7 +70,7 @@ 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": "$pk"}).then((var parts) { InvenTreePart().list(context, filters: {"category": "$pk"}).then((var parts) {
_parts.clear(); _parts.clear();
for (var part in parts) { for (var part in parts) {

View File

@ -46,7 +46,7 @@ class _CompanyListState extends State<CompanyListWidget> {
void _requestData() { void _requestData() {
InvenTreeCompany().list(filters: _filters).then((var companies) { InvenTreeCompany().list(context, filters: _filters).then((var companies) {
_companies.clear(); _companies.clear();

View File

@ -22,6 +22,7 @@ void showErrorDialog(BuildContext context, String title, String description) {
} }
void showProgressDialog(BuildContext context, String title, String description) { void showProgressDialog(BuildContext context, String title, String description) {
showDialog( showDialog(
context: context, context: context,
barrierDismissible: false, barrierDismissible: false,

View File

@ -10,6 +10,8 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart';
class LocationDisplayWidget extends StatefulWidget { class LocationDisplayWidget extends StatefulWidget {
LocationDisplayWidget(this.location, {Key key}) : super(key: key); LocationDisplayWidget(this.location, {Key key}) : super(key: key);
final InvenTreeStockLocation location; final InvenTreeStockLocation location;
@ -23,8 +25,15 @@ class LocationDisplayWidget extends StatefulWidget {
class _LocationDisplayState extends State<LocationDisplayWidget> { class _LocationDisplayState extends State<LocationDisplayWidget> {
BuildContext context;
_LocationDisplayState(this.location) { _LocationDisplayState(this.location) {
_requestData();
}
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) => _requestData(context));
} }
final InvenTreeStockLocation location; final InvenTreeStockLocation location;
@ -60,12 +69,14 @@ class _LocationDisplayState extends State<LocationDisplayWidget> {
* - List of sublocations under this one * - List of sublocations under this one
* - List of stock items at this location * - List of stock items at this location
*/ */
void _requestData() { void _requestData(BuildContext context) {
print("Requesting data!");
int pk = location?.pk ?? -1; int pk = location?.pk ?? -1;
// Request a list of sub-locations under this one // 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(); _sublocations.clear();
for (var loc in locs) { for (var loc in locs) {
@ -76,18 +87,18 @@ class _LocationDisplayState extends State<LocationDisplayWidget> {
setState(() {}); setState(() {});
// Request a list of stock-items under this one // Request a list of stock-items under this one
InvenTreeStockItem().list(filters: {"location": "$pk"}).then((var items) { InvenTreeStockItem().list(context, filters: {"location": "$pk"}).then((var items) {
_items.clear(); _items.clear();
for (var item in items) { for (var item in items) {
if (item is InvenTreeStockItem) { if (item is InvenTreeStockItem) {
_items.add(item); _items.add(item);
}
} }
}
setState(() {}); setState(() {});
}); });
}); });
} }
@ -135,6 +146,12 @@ class _LocationDisplayState extends State<LocationDisplayWidget> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// Save the context
this.context = context;
print("Saved context!");
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text(_title), title: Text(_title),