From 3fead77f6d169210af3d1cf0e3daaea38275806f Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 15 Apr 2020 10:33:10 +1000 Subject: [PATCH] Capture context data in the LocationDisplay widget --- lib/inventree/model.dart | 2 ++ lib/inventree/part.dart | 2 +- lib/main.dart | 46 +++++--------------------------- lib/widget/category_display.dart | 4 +-- lib/widget/company_list.dart | 2 +- lib/widget/dialogs.dart | 1 + lib/widget/location_display.dart | 41 +++++++++++++++++++--------- 7 files changed, 42 insertions(+), 56 deletions(-) diff --git a/lib/inventree/model.dart b/lib/inventree/model.dart index 5f541361..05750586 100644 --- a/lib/inventree/model.dart +++ b/lib/inventree/model.dart @@ -201,6 +201,8 @@ class InvenTreeModel { return null; } + hideProgressDialog(context); + // A list of "InvenTreeModel" items List results = new List(); diff --git a/lib/inventree/part.dart b/lib/inventree/part.dart index 4732fa2a..d3b3e269 100644 --- a/lib/inventree/part.dart +++ b/lib/inventree/part.dart @@ -66,7 +66,7 @@ class InvenTreePartCategory extends InvenTreeModel { class InvenTreePart extends InvenTreeModel { @override - String Name = "Part"; + String NAME = "Part"; @override String URL = "part/"; diff --git a/lib/main.dart b/lib/main.dart index 4dd424d9..a15fb541 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -22,6 +22,8 @@ import 'preferences.dart'; import 'package:InvenTree/inventree/part.dart'; + + void main() async { // await PrefService.init(prefix: "inventree_"); @@ -31,10 +33,10 @@ void main() async { // Load login details InvenTreePreferences().loadLoginDetails(); - runApp(MyApp()); + runApp(InvenTreeApp()); } -class MyApp extends StatelessWidget { +class InvenTreeApp extends StatelessWidget { // This widget is the root of your application. @override @@ -42,16 +44,8 @@ class MyApp extends StatelessWidget { return MaterialApp( title: 'InvenTree', theme: ThemeData( - // This is the theme of your application. - // - // 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, + primarySwatch: Colors.lightBlue, + secondaryHeaderColor: Colors.blueGrey, ), home: MyHomePage(title: 'InvenTree'), ); @@ -59,34 +53,6 @@ class MyApp extends StatelessWidget { } -class ProductList extends StatelessWidget { - final List _parts; - - ProductList(this._parts); - - Widget _buildPart(BuildContext context, int index) { - InvenTreePart part; - - if (index < _parts.length) { - part = _parts[index]; - } - - return Card( - child: Column( - children: [ - Text('${part.name} - ${part.description}'), - ] - ) - ); - } - - @override - Widget build(BuildContext context) { - return ListView.builder(itemBuilder: _buildPart, itemCount: _parts.length); - } -} - - class MyHomePage extends StatefulWidget { MyHomePage({Key key, this.title}) : super(key: key); diff --git a/lib/widget/category_display.dart b/lib/widget/category_display.dart index 4de2ac42..cbda3091 100644 --- a/lib/widget/category_display.dart +++ b/lib/widget/category_display.dart @@ -56,7 +56,7 @@ class _CategoryDisplayState extends State { 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 { }); // 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) { diff --git a/lib/widget/company_list.dart b/lib/widget/company_list.dart index 760a9b8c..8402b3aa 100644 --- a/lib/widget/company_list.dart +++ b/lib/widget/company_list.dart @@ -46,7 +46,7 @@ class _CompanyListState extends State { void _requestData() { - InvenTreeCompany().list(filters: _filters).then((var companies) { + InvenTreeCompany().list(context, filters: _filters).then((var companies) { _companies.clear(); diff --git a/lib/widget/dialogs.dart b/lib/widget/dialogs.dart index db6a0eae..ceb94158 100644 --- a/lib/widget/dialogs.dart +++ b/lib/widget/dialogs.dart @@ -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, diff --git a/lib/widget/location_display.dart b/lib/widget/location_display.dart index 15b970f1..29d91b15 100644 --- a/lib/widget/location_display.dart +++ b/lib/widget/location_display.dart @@ -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 { + 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 { * - 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 { 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 { @override Widget build(BuildContext context) { + + // Save the context + this.context = context; + + print("Saved context!"); + return Scaffold( appBar: AppBar( title: Text(_title),