From 11c8a5567750533d41898e17979a365470981b81 Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 27 Sep 2021 22:34:55 +1000 Subject: [PATCH] Refactor the "home" page - Use a grid view instead of hard-coded columns - Aware of the screen orientation --- lib/widget/home.dart | 294 ++++++++++++++++++++----------------------- 1 file changed, 133 insertions(+), 161 deletions(-) diff --git a/lib/widget/home.dart b/lib/widget/home.dart index 08c3a5ef..39991a1d 100644 --- a/lib/widget/home.dart +++ b/lib/widget/home.dart @@ -183,6 +183,27 @@ class _InvenTreeHomePageState extends State { } } + Widget _iconButton(String label, IconData icon, {Function()? callback}) { + + return GestureDetector( + child: Card( + margin: EdgeInsets.symmetric( + vertical: 10, + horizontal: 10 + ), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + FaIcon(icon), + Text(label), + ] + ) + ), + onTap: callback, + ); + + } + @override Widget build(BuildContext context) { @@ -207,184 +228,135 @@ class _InvenTreeHomePageState extends State { ], ), drawer: new InvenTreeDrawer(context), - body: Center( - // Center is a layout widget. It takes a single child and positions it - // in the middle of the parent. - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: ([ - Spacer(), - Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - Column( - children: [ - IconButton( - icon: new FaIcon(FontAwesomeIcons.barcode), - tooltip: L10().scanBarcode, - onPressed: () { _scan(context); }, - ), - Text(L10().scanBarcode), - ], - ), - ], + body: GridView.count( + crossAxisCount: MediaQuery.of(context).orientation == Orientation.portrait ? 3 : 5, + shrinkWrap: true, + physics: ClampingScrollPhysics(), + children: [ + _iconButton( + L10().scanBarcode, + FontAwesomeIcons.barcode, + callback: () { + _scan(context); + } ), - Spacer(), - Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - Column( - children: [ - IconButton( - icon: new FaIcon(FontAwesomeIcons.shapes), - tooltip: L10().parts, - onPressed: () { _parts(context); }, - ), - Text(L10().parts), - ], - ), - Column( - children: [ - - IconButton( - icon: new FaIcon(FontAwesomeIcons.search), - tooltip: L10().searchParts, - onPressed: _searchParts, - ), - Text(L10().searchParts), - ], - ), - // TODO - Re-add starred parts link - /* - Column( - children: [ - IconButton( - icon: FaIcon(FontAwesomeIcons.solidStar), - onPressed: () { - Navigator.push(context, MaterialPageRoute(builder: (context) => StarredPartWidget())); - }, - ), - Text("Starred Parts"), - ] - ), - */ - ], + _iconButton( + L10().parts, + FontAwesomeIcons.shapes, + callback: () { + _parts(context); + } ), - Spacer(), - Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, + _iconButton( + L10().searchParts, + FontAwesomeIcons.search, + callback: () { + _searchParts(); + } + ), + // TODO - Re-add starred parts link + /* + Column( children: [ - Column( - children: [ - IconButton( - icon: new FaIcon(FontAwesomeIcons.boxes), - tooltip: L10().stock, - onPressed: () { _stock(context); }, - ), - Text(L10().stock), - ], - ), - Column( - children: [ - IconButton( - icon: new FaIcon(FontAwesomeIcons.search), - tooltip: L10().searchStock, - onPressed: _searchStock, - ), - Text(L10().searchStock), - ], + IconButton( + icon: FaIcon(FontAwesomeIcons.solidStar), + onPressed: () { + Navigator.push(context, MaterialPageRoute(builder: (context) => StarredPartWidget())); + }, ), + Text("Starred Parts"), ] ), - Spacer(), - // TODO - Re-add these when the features actually do something.. + */ + _iconButton( + L10().stock, + FontAwesomeIcons.boxes, + callback: () { + _stock(context); + } + ), + _iconButton( + L10().searchStock, + FontAwesomeIcons.search, + callback: () { + _searchStock(); + } + ), + _iconButton( + L10().purchaseOrders, + FontAwesomeIcons.shoppingCart, + callback: () { + // TODO + } + ), + _iconButton( + L10().suppliers, + FontAwesomeIcons.building, + callback: () { + _suppliers(); + } + ), + _iconButton( + L10().manufacturers, + FontAwesomeIcons.industry, + callback: () { + // TODO + } + ), /* - Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, + Spacer(), + Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + Column( children: [ - Column( - children: [ - IconButton( - icon: new FaIcon(FontAwesomeIcons.building), - tooltip: "Suppliers", - onPressed: _suppliers, - ), - Text("Suppliers"), - ], + IconButton( + icon: new FaIcon(FontAwesomeIcons.tools), + tooltip: "Build", + onPressed: _unsupported, ), - Column( - children: [ - IconButton( - icon: FaIcon(FontAwesomeIcons.industry), - tooltip: "Manufacturers", - onPressed: _manufacturers, - ), - Text("Manufacturers") - ], - ), - Column( - children: [ - IconButton( - icon: FaIcon(FontAwesomeIcons.userTie), - tooltip: "Customers", - onPressed: _customers, - ), - Text("Customers"), - ] - ) + Text("Build"), ], ), - Spacer(), - Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, + Column( children: [ - Column( - children: [ - IconButton( - icon: new FaIcon(FontAwesomeIcons.tools), - tooltip: "Build", - onPressed: _unsupported, - ), - Text("Build"), - ], + IconButton( + icon: new FaIcon(FontAwesomeIcons.shoppingCart), + tooltip: "Order", + onPressed: _unsupported, ), - Column( - children: [ - IconButton( - icon: new FaIcon(FontAwesomeIcons.shoppingCart), - tooltip: "Order", - onPressed: _unsupported, - ), - Text("Order"), - ] - ), - Column( - children: [ - IconButton( - icon: new FaIcon(FontAwesomeIcons.truck), - tooltip: "Ship", - onPressed: _unsupported, - ), - Text("Ship"), - ] - ) - ], + Text("Order"), + ] ), - Spacer(), - */ - Spacer(), - Row( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, + Column( children: [ - Expanded( - child: _serverTile(), + IconButton( + icon: new FaIcon(FontAwesomeIcons.truck), + tooltip: "Ship", + onPressed: _unsupported, ), - ], - ), - ]), + Text("Ship"), + ] + ) + ], ), - ), + Spacer(), + */ + /* + Spacer(), + Row( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Expanded( + child: _serverTile(), + ), + ], + ), + ]), + */ + ], + ) ); } }