mirror of
				https://github.com/inventree/inventree-app.git
				synced 2025-10-30 21:05:42 +00:00 
			
		
		
		
	Capture context data in the LocationDisplay widget
This commit is contained in:
		| @@ -201,6 +201,8 @@ class InvenTreeModel { | ||||
|       return null; | ||||
|     } | ||||
|  | ||||
|     hideProgressDialog(context); | ||||
|  | ||||
|     // A list of "InvenTreeModel" items | ||||
|     List<InvenTreeModel> results = new List<InvenTreeModel>(); | ||||
|  | ||||
|   | ||||
| @@ -66,7 +66,7 @@ class InvenTreePartCategory extends InvenTreeModel { | ||||
| class InvenTreePart extends InvenTreeModel { | ||||
|  | ||||
|   @override | ||||
|   String Name = "Part"; | ||||
|   String NAME = "Part"; | ||||
|  | ||||
|   @override | ||||
|   String URL = "part/"; | ||||
|   | ||||
| @@ -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<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 { | ||||
|   MyHomePage({Key key, this.title}) : super(key: key); | ||||
|  | ||||
|   | ||||
| @@ -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