2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-28 13:36:50 +00:00

Add "pull to refresh" for location_display widget

This commit is contained in:
Oliver Walters 2020-04-15 11:04:27 +10:00
parent 3fead77f6d
commit 5cc80ee3f4

View File

@ -28,7 +28,6 @@ class _LocationDisplayState extends State<LocationDisplayWidget> {
BuildContext context; BuildContext context;
_LocationDisplayState(this.location) { _LocationDisplayState(this.location) {
} }
void initState() { void initState() {
@ -62,6 +61,10 @@ class _LocationDisplayState extends State<LocationDisplayWidget> {
} }
} }
Future<void> _refresh() async {
await _requestData(context);
}
/* /*
* Request data from the server. * Request data from the server.
* It will be displayed once loaded * It will be displayed once loaded
@ -69,9 +72,7 @@ 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(BuildContext context) { Future<void> _requestData(BuildContext context) async {
print("Requesting data!");
int pk = location?.pk ?? -1; int pk = location?.pk ?? -1;
@ -150,68 +151,69 @@ class _LocationDisplayState extends State<LocationDisplayWidget> {
// Save the context // Save the context
this.context = context; this.context = context;
print("Saved context!");
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text(_title), title: Text(_title),
), ),
drawer: new InvenTreeDrawer(context), drawer: new InvenTreeDrawer(context),
body: ListView( body: new RefreshIndicator(
children: <Widget> [ onRefresh: _refresh,
locationDescriptionCard(), child: ListView(
ExpansionPanelList( children: <Widget> [
expansionCallback: (int index, bool isExpanded) { locationDescriptionCard(),
setState(() { ExpansionPanelList(
switch (index) { expansionCallback: (int index, bool isExpanded) {
case 0: setState(() {
InvenTreePreferences().expandLocationList = !isExpanded; switch (index) {
break; case 0:
case 1: InvenTreePreferences().expandLocationList = !isExpanded;
InvenTreePreferences().expandStockList = !isExpanded; break;
break; case 1:
default: InvenTreePreferences().expandStockList = !isExpanded;
break; break;
} default:
}); break;
}
});
}, },
children: <ExpansionPanel> [ children: <ExpansionPanel> [
ExpansionPanel( ExpansionPanel(
headerBuilder: (BuildContext context, bool isExpanded) { headerBuilder: (BuildContext context, bool isExpanded) {
return ListTile( return ListTile(
title: Text("Sublocations"), title: Text("Sublocations"),
leading: FaIcon(FontAwesomeIcons.mapMarkerAlt), leading: FaIcon(FontAwesomeIcons.mapMarkerAlt),
trailing: Text("${_sublocations.length}"), trailing: Text("${_sublocations.length}"),
onTap: () { onTap: () {
setState(() { setState(() {
InvenTreePreferences().expandLocationList = !InvenTreePreferences().expandLocationList; InvenTreePreferences().expandLocationList = !InvenTreePreferences().expandLocationList;
}); });
}, },
); );
}, },
body: SublocationList(_sublocations), body: SublocationList(_sublocations),
isExpanded: InvenTreePreferences().expandLocationList && _sublocations.length > 0, isExpanded: InvenTreePreferences().expandLocationList && _sublocations.length > 0,
), ),
ExpansionPanel( ExpansionPanel(
headerBuilder: (BuildContext context, bool isExpanded) { headerBuilder: (BuildContext context, bool isExpanded) {
return ListTile( return ListTile(
title: Text("Stock Items"), title: Text("Stock Items"),
leading: FaIcon(FontAwesomeIcons.boxes), leading: FaIcon(FontAwesomeIcons.boxes),
trailing: Text("${_items.length}"), trailing: Text("${_items.length}"),
onTap: () { onTap: () {
setState(() { setState(() {
InvenTreePreferences().expandStockList = !InvenTreePreferences().expandStockList; InvenTreePreferences().expandStockList = !InvenTreePreferences().expandStockList;
}); });
}, },
); );
}, },
body: StockList(_items), body: StockList(_items),
isExpanded: InvenTreePreferences().expandStockList && _items.length > 0, isExpanded: InvenTreePreferences().expandStockList && _items.length > 0,
) )
] ]
), ),
] ]
)
) )
); );
} }