From 90a39ae3de2359c4b98336c239d6d1fa98e87505 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 15 Apr 2020 12:07:36 +1000 Subject: [PATCH] Company list is now refreshable --- lib/widget/category_display.dart | 2 +- lib/widget/company_list.dart | 63 +++++++++++++------------------ lib/widget/location_display.dart | 2 +- lib/widget/part_detail.dart | 2 +- lib/widget/refreshable_state.dart | 4 +- lib/widget/stock_detail.dart | 2 +- 6 files changed, 32 insertions(+), 43 deletions(-) diff --git a/lib/widget/category_display.dart b/lib/widget/category_display.dart index a1328b18..46a04bde 100644 --- a/lib/widget/category_display.dart +++ b/lib/widget/category_display.dart @@ -30,7 +30,7 @@ class CategoryDisplayWidget extends StatefulWidget { class _CategoryDisplayState extends RefreshableState { @override - String app_bar_title = "Part Category"; + String getAppBarTitle(BuildContext context) { return "Part Category"; } _CategoryDisplayState(this.category) {} diff --git a/lib/widget/company_list.dart b/lib/widget/company_list.dart index 8402b3aa..767b8a79 100644 --- a/lib/widget/company_list.dart +++ b/lib/widget/company_list.dart @@ -6,6 +6,7 @@ import 'package:flutter/material.dart'; import 'package:InvenTree/api.dart'; import 'package:InvenTree/inventree/company.dart'; import 'package:InvenTree/widget/drawer.dart'; +import 'package:InvenTree/widget/refreshable_state.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; abstract class CompanyListWidget extends StatefulWidget { @@ -30,21 +31,23 @@ class CustomerListWidget extends CompanyListWidget { } -class _CompanyListState extends State { +class _CompanyListState extends RefreshableState { var _companies = new List(); var _filteredCompanies = new List(); - var _title = "Companies"; + String _title = "Companies"; + + @override + String getAppBarTitle(BuildContext context) { return _title; } Map _filters = Map(); - _CompanyListState(this._title, this._filters) { - _requestData(); - } + _CompanyListState(this._title, this._filters) {} - void _requestData() { + @override + Future request(BuildContext context) async { InvenTreeCompany().list(context, filters: _filters).then((var companies) { @@ -94,38 +97,24 @@ class _CompanyListState extends State { } @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: Text("$_title"), - actions: [ - IconButton( - icon: FaIcon(FontAwesomeIcons.plus), - tooltip: 'New', - onPressed: null, - ) - ], + Widget getBody(BuildContext context) { + return ListView( + children: [ + TextField( + decoration: InputDecoration( + hintText: 'Filter results', + ), + onChanged: (String text) { + setState(() { + _filterResults(text); + }); + }, ), - drawer: new InvenTreeDrawer(context), - body: ListView( - children: [ - TextField( - decoration: InputDecoration( - hintText: 'Filter results', - ), - onChanged: (String text) { - setState(() { - _filterResults(text); - }); - }, - ), - ListView.builder( - shrinkWrap: true, - physics: ClampingScrollPhysics(), - itemBuilder: _showCompany, itemCount: _filteredCompanies.length) - ], - ) + ListView.builder( + shrinkWrap: true, + physics: ClampingScrollPhysics(), + itemBuilder: _showCompany, itemCount: _filteredCompanies.length) + ], ); } - } \ No newline at end of file diff --git a/lib/widget/location_display.dart b/lib/widget/location_display.dart index 7bb71d7c..84362689 100644 --- a/lib/widget/location_display.dart +++ b/lib/widget/location_display.dart @@ -27,7 +27,7 @@ class _LocationDisplayState extends RefreshableState { final InvenTreeStockLocation location; @override - String app_bar_title = "Stock Location"; + String getAppBarTitle(BuildContext context) { return "Stock Location"; } _LocationDisplayState(this.location) {} diff --git a/lib/widget/part_detail.dart b/lib/widget/part_detail.dart index 41211f86..4efc7a69 100644 --- a/lib/widget/part_detail.dart +++ b/lib/widget/part_detail.dart @@ -25,7 +25,7 @@ class PartDetailWidget extends StatefulWidget { class _PartDisplayState extends RefreshableState { @override - String app_bar_title = "Part"; + String getAppBarTitle(BuildContext context) { return "Part"; } _PartDisplayState(this.part) { // TODO diff --git a/lib/widget/refreshable_state.dart b/lib/widget/refreshable_state.dart index 426254d6..bfb061ef 100644 --- a/lib/widget/refreshable_state.dart +++ b/lib/widget/refreshable_state.dart @@ -11,7 +11,7 @@ abstract class RefreshableState extends State { // Storage for context once "Build" is called BuildContext context; - String app_bar_title = "App Bar Title"; + String getAppBarTitle(BuildContext context) { return "App Bar Title"; } void initState() { super.initState(); @@ -31,7 +31,7 @@ abstract class RefreshableState extends State { // Function to construct an appbar (override if needed) AppBar getAppBar(BuildContext context) { return AppBar( - title: Text(app_bar_title) + title: Text(getAppBarTitle(context)) ); } diff --git a/lib/widget/stock_detail.dart b/lib/widget/stock_detail.dart index c180bba9..e77e6cc8 100644 --- a/lib/widget/stock_detail.dart +++ b/lib/widget/stock_detail.dart @@ -31,7 +31,7 @@ class StockDetailWidget extends StatefulWidget { class _StockItemDisplayState extends RefreshableState { @override - String app_bar_title = "Stock Item"; + String getAppBarTitle(BuildContext context) { return "Stock Item"; } final TextEditingController _quantityController = TextEditingController(); final TextEditingController _notesController = TextEditingController();