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

Cleanup home page widget

This commit is contained in:
Oliver 2021-09-28 12:05:44 +10:00
parent 54d8c1759c
commit c1a1ef0ad2
3 changed files with 78 additions and 70 deletions

View File

@ -240,7 +240,7 @@ class InvenTreeAPI {
if (address.isEmpty || username.isEmpty || password.isEmpty) { if (address.isEmpty || username.isEmpty || password.isEmpty) {
showSnackIcon( showSnackIcon(
"Incomplete profile details", L10().incompleteDetails,
icon: FontAwesomeIcons.exclamationCircle, icon: FontAwesomeIcons.exclamationCircle,
success: false success: false
); );

@ -1 +1 @@
Subproject commit dba9551b897dca766088e5470704e20edb770499 Subproject commit ed69d6efe7672770ee27f4d1b4fc8ab7793266da

View File

@ -17,6 +17,7 @@ import 'package:inventree/widget/company_list.dart';
import 'package:inventree/widget/location_display.dart'; import 'package:inventree/widget/location_display.dart';
import 'package:inventree/widget/purchase_order_list.dart'; import 'package:inventree/widget/purchase_order_list.dart';
import 'package:inventree/widget/search.dart'; import 'package:inventree/widget/search.dart';
import 'package:inventree/widget/snacks.dart';
import 'package:inventree/widget/spinner.dart'; import 'package:inventree/widget/spinner.dart';
import 'package:inventree/widget/drawer.dart'; import 'package:inventree/widget/drawer.dart';
@ -204,37 +205,15 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> {
} }
} }
Widget _header(String label) { Widget _iconButton(BuildContext context, String label, IconData icon, {Function()? callback, String role = "", String permission = ""}) {
return Card(
margin: EdgeInsets.symmetric(
vertical: 1,
horizontal: 10,
),
child: ListTile(
contentPadding: EdgeInsets.symmetric(
horizontal: 10,
vertical: 1
),
title: Text(
label,
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
),
);
}
Widget _grid(List<Widget> children) { bool connected = InvenTreeAPI().isConnected();
return GridView.extent(
maxCrossAxisExtent: 140,
shrinkWrap: true,
physics: ClampingScrollPhysics(),
children: children,
);
}
Widget _iconButton(String label, IconData icon, {Function()? callback}) { bool allowed = true;
if (role.isNotEmpty || permission.isNotEmpty) {
allowed = InvenTreeAPI().checkPermission(role, permission);
}
return GestureDetector( return GestureDetector(
child: Card( child: Card(
@ -247,7 +226,7 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> {
children: [ children: [
FaIcon( FaIcon(
icon, icon,
color: callback == null ? Colors.grey : COLOR_CLICK, color: connected && allowed ? COLOR_CLICK : Colors.grey,
), ),
Divider( Divider(
height: 10, height: 10,
@ -258,11 +237,27 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> {
] ]
) )
), ),
onTap: callback, onTap: () {
if (!allowed) {
showSnackIcon(
L10().permissionRequired,
icon: FontAwesomeIcons.exclamationCircle,
success: false,
); );
return;
} }
if (callback != null) {
callback();
}
},
);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -291,8 +286,13 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> {
physics: ClampingScrollPhysics(), physics: ClampingScrollPhysics(),
shrinkWrap: true, shrinkWrap: true,
children: [ children: [
_grid([ GridView.extent(
maxCrossAxisExtent: 140,
shrinkWrap: true,
physics: ClampingScrollPhysics(),
children: [
_iconButton( _iconButton(
context,
L10().scanBarcode, L10().scanBarcode,
FontAwesomeIcons.barcode, FontAwesomeIcons.barcode,
callback: () { callback: () {
@ -300,6 +300,7 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> {
} }
), ),
_iconButton( _iconButton(
context,
L10().search, L10().search,
FontAwesomeIcons.search, FontAwesomeIcons.search,
callback: () { callback: () {
@ -307,6 +308,7 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> {
} }
), ),
_iconButton( _iconButton(
context,
L10().parts, L10().parts,
FontAwesomeIcons.shapes, FontAwesomeIcons.shapes,
callback: () { callback: () {
@ -330,6 +332,7 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> {
*/ */
_iconButton( _iconButton(
context,
L10().stock, L10().stock,
FontAwesomeIcons.boxes, FontAwesomeIcons.boxes,
callback: () { callback: () {
@ -337,6 +340,7 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> {
} }
), ),
_iconButton( _iconButton(
context,
L10().purchaseOrders, L10().purchaseOrders,
FontAwesomeIcons.shoppingCart, FontAwesomeIcons.shoppingCart,
callback: () { callback: () {
@ -344,10 +348,12 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> {
} }
), ),
_iconButton( _iconButton(
context,
L10().salesOrders, L10().salesOrders,
FontAwesomeIcons.truck, FontAwesomeIcons.truck,
), ),
_iconButton( _iconButton(
context,
L10().suppliers, L10().suppliers,
FontAwesomeIcons.building, FontAwesomeIcons.building,
callback: () { callback: () {
@ -355,6 +361,7 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> {
} }
), ),
_iconButton( _iconButton(
context,
L10().manufacturers, L10().manufacturers,
FontAwesomeIcons.industry, FontAwesomeIcons.industry,
callback: () { callback: () {
@ -362,6 +369,7 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> {
} }
), ),
_iconButton( _iconButton(
context,
L10().customers, L10().customers,
FontAwesomeIcons.userTie, FontAwesomeIcons.userTie,
callback: () { callback: () {