From 3433d57f8387d5379a81c958476442a4e28bcc85 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 29 Jan 2021 00:52:15 +1100 Subject: [PATCH] Refactor display for StockLocation --- lib/barcode.dart | 10 ++ lib/widget/location_display.dart | 153 +++++++++++++++++++++++-------- 2 files changed, 124 insertions(+), 39 deletions(-) diff --git a/lib/barcode.dart b/lib/barcode.dart index 2beaad2f..f92c9ae7 100644 --- a/lib/barcode.dart +++ b/lib/barcode.dart @@ -41,6 +41,16 @@ class BarcodeHandler { Future onBarcodeUnknown(Map data) { // Called when the server does not know about a barcode // Override this function + showErrorDialog( + _context, + "Invalid Barcode", + "Barcode does not match any known item", + error: "Barcode Error", + icon: FontAwesomeIcons.barcode, + onDismissed: () { + _controller.resumeCamera(); + } + ); } Future onBarcodeUnhandled(Map data) { diff --git a/lib/widget/location_display.dart b/lib/widget/location_display.dart index d61c8a70..49223c14 100644 --- a/lib/widget/location_display.dart +++ b/lib/widget/location_display.dart @@ -133,11 +133,87 @@ class _LocationDisplayState extends RefreshableState { } @override - Widget getBody(BuildContext context) { + Widget getBottomNavBar(BuildContext context) { + return BottomNavigationBar( + currentIndex: tabIndex, + onTap: onTabSelectionChanged, + items: const [ + BottomNavigationBarItem( + icon: FaIcon(FontAwesomeIcons.boxes), + title: Text("Stock"), + ), + BottomNavigationBarItem( + icon: FaIcon(FontAwesomeIcons.wrench), + title: Text("Actions"), + ) + ] + ); + } - return ListView( - children: [ - locationDescriptionCard(), + Widget getSelectedWidget(int index) { + switch (index) { + case 0: + return ListView( + children: detailTiles(), + ); + case 1: + return ListView( + children: actionTiles(), + ); + default: + return null; + } + } + + @override + Widget getBody(BuildContext context) { + return getSelectedWidget(tabIndex); + } + + +List detailTiles() { + List tiles = []; + + // Location description + tiles.add(locationDescriptionCard()); + + // Sublocation panel + ExpansionPanel sublocations = ExpansionPanel( + headerBuilder: (BuildContext context, bool isExpanded) { + return ListTile( + title: Text("Sublocations"), + leading: FaIcon(FontAwesomeIcons.mapMarkerAlt), + trailing: Text("${_sublocations.length}"), + onTap: () { + setState(() { + InvenTreePreferences().expandLocationList = !InvenTreePreferences().expandLocationList; + }); + }, + ); + }, + body: SublocationList(_sublocations), + isExpanded: InvenTreePreferences().expandLocationList && _sublocations.length > 0, + ); + + ExpansionPanel subitems = ExpansionPanel( + headerBuilder: (BuildContext context, bool isExpanded) { + return ListTile( + title: Text("Stock Items"), + leading: FaIcon(FontAwesomeIcons.boxes), + trailing: Text("${_items.length}"), + onTap: () { + setState(() { + InvenTreePreferences().expandStockList = !InvenTreePreferences().expandStockList; + }); + }, + ); + }, + body: StockList(_items), + isExpanded: InvenTreePreferences().expandStockList && _items.length > 0, + ); + + // Sublocations and items + tiles.add( ExpansionPanelList( expansionCallback: (int index, bool isExpanded) { setState(() { @@ -152,49 +228,48 @@ class _LocationDisplayState extends RefreshableState { break; } }); - }, children: [ - ExpansionPanel( - headerBuilder: (BuildContext context, bool isExpanded) { - return ListTile( - title: Text("Sublocations"), - leading: FaIcon(FontAwesomeIcons.mapMarkerAlt), - trailing: Text("${_sublocations.length}"), - onTap: () { - setState(() { - InvenTreePreferences().expandLocationList = !InvenTreePreferences().expandLocationList; - }); - }, - ); - }, - body: SublocationList(_sublocations), - isExpanded: InvenTreePreferences().expandLocationList && _sublocations.length > 0, - ), - ExpansionPanel( - headerBuilder: (BuildContext context, bool isExpanded) { - return ListTile( - title: Text("Stock Items"), - leading: FaIcon(FontAwesomeIcons.boxes), - trailing: Text("${_items.length}"), - onTap: () { - setState(() { - InvenTreePreferences().expandStockList = !InvenTreePreferences().expandStockList; - }); - }, - ); - }, - body: StockList(_items), - isExpanded: InvenTreePreferences().expandStockList && _items.length > 0, - ) + sublocations, + subitems, ] - ), - ] + ) ); + + return tiles; } + + List actionTiles() { + List tiles = []; + + tiles.add(locationDescriptionCard()); + + // Scan items into location + tiles.add( + ListTile( + title: Text("Scan in Stock Item"), + leading: FaIcon(FontAwesomeIcons.exchangeAlt), + trailing: FaIcon(FontAwesomeIcons.qrcode), + onTap: null, + ) + ); + + // Move location into another location + tiles.add( + ListTile( + title: Text("Move Stock Location"), + leading: FaIcon(FontAwesomeIcons.sitemap), + trailing: FaIcon(FontAwesomeIcons.qrcode), + ) + ); + + return tiles; + } + } + class SublocationList extends StatelessWidget { final List _locations;