2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-06-13 18:55:34 +00:00

Refactor the "home" page

- Use a grid view instead of hard-coded columns
- Aware of the screen orientation
This commit is contained in:
Oliver
2021-09-27 22:34:55 +10:00
parent f9b688cdab
commit 11c8a55677

View File

@ -183,6 +183,27 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> {
} }
} }
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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -207,52 +228,31 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> {
], ],
), ),
drawer: new InvenTreeDrawer(context), drawer: new InvenTreeDrawer(context),
body: Center( body: GridView.count(
// Center is a layout widget. It takes a single child and positions it crossAxisCount: MediaQuery.of(context).orientation == Orientation.portrait ? 3 : 5,
// in the middle of the parent. shrinkWrap: true,
child: Column( physics: ClampingScrollPhysics(),
mainAxisAlignment: MainAxisAlignment.center, children: [
children: (<Widget>[ _iconButton(
Spacer(), L10().scanBarcode,
Row( FontAwesomeIcons.barcode,
mainAxisAlignment: MainAxisAlignment.spaceEvenly, callback: () {
children: <Widget>[ _scan(context);
Column( }
children: <Widget>[
IconButton(
icon: new FaIcon(FontAwesomeIcons.barcode),
tooltip: L10().scanBarcode,
onPressed: () { _scan(context); },
), ),
Text(L10().scanBarcode), _iconButton(
], L10().parts,
FontAwesomeIcons.shapes,
callback: () {
_parts(context);
}
), ),
], _iconButton(
), L10().searchParts,
Spacer(), FontAwesomeIcons.search,
Row( callback: () {
mainAxisAlignment: MainAxisAlignment.spaceEvenly, _searchParts();
children: <Widget>[ }
Column(
children: <Widget>[
IconButton(
icon: new FaIcon(FontAwesomeIcons.shapes),
tooltip: L10().parts,
onPressed: () { _parts(context); },
),
Text(L10().parts),
],
),
Column(
children: <Widget>[
IconButton(
icon: new FaIcon(FontAwesomeIcons.search),
tooltip: L10().searchParts,
onPressed: _searchParts,
),
Text(L10().searchParts),
],
), ),
// TODO - Re-add starred parts link // TODO - Re-add starred parts link
/* /*
@ -268,72 +268,42 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> {
] ]
), ),
*/ */
], _iconButton(
L10().stock,
FontAwesomeIcons.boxes,
callback: () {
_stock(context);
}
), ),
Spacer(), _iconButton(
Row( L10().searchStock,
mainAxisAlignment: MainAxisAlignment.spaceEvenly, FontAwesomeIcons.search,
children: <Widget>[ callback: () {
Column( _searchStock();
children: <Widget>[ }
IconButton(
icon: new FaIcon(FontAwesomeIcons.boxes),
tooltip: L10().stock,
onPressed: () { _stock(context); },
), ),
Text(L10().stock), _iconButton(
], L10().purchaseOrders,
FontAwesomeIcons.shoppingCart,
callback: () {
// TODO
}
), ),
Column( _iconButton(
children: <Widget>[ L10().suppliers,
IconButton( FontAwesomeIcons.building,
icon: new FaIcon(FontAwesomeIcons.search), callback: () {
tooltip: L10().searchStock, _suppliers();
onPressed: _searchStock, }
), ),
Text(L10().searchStock), _iconButton(
], L10().manufacturers,
FontAwesomeIcons.industry,
callback: () {
// TODO
}
), ),
]
),
Spacer(),
// TODO - Re-add these when the features actually do something..
/* /*
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Column(
children: <Widget>[
IconButton(
icon: new FaIcon(FontAwesomeIcons.building),
tooltip: "Suppliers",
onPressed: _suppliers,
),
Text("Suppliers"),
],
),
Column(
children: <Widget>[
IconButton(
icon: FaIcon(FontAwesomeIcons.industry),
tooltip: "Manufacturers",
onPressed: _manufacturers,
),
Text("Manufacturers")
],
),
Column(
children: <Widget>[
IconButton(
icon: FaIcon(FontAwesomeIcons.userTie),
tooltip: "Customers",
onPressed: _customers,
),
Text("Customers"),
]
)
],
),
Spacer(), Spacer(),
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
@ -372,6 +342,7 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> {
), ),
Spacer(), Spacer(),
*/ */
/*
Spacer(), Spacer(),
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
@ -383,8 +354,9 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> {
], ],
), ),
]), ]),
), */
), ],
)
); );
} }
} }