mirror of
https://github.com/inventree/inventree-app.git
synced 2025-07-01 11:20:41 +00:00
Format Code and Add Format Checks to CI (#643)
* Remove unused lib/generated/i18n.dart * Use `fvm dart format .` * Add contributing guidelines * Enforce dart format * Add `dart format off` directive to generated files
This commit is contained in:
@ -26,18 +26,15 @@ import "package:inventree/widget/snacks.dart";
|
||||
import "package:inventree/widget/spinner.dart";
|
||||
import "package:inventree/widget/company/company_list.dart";
|
||||
|
||||
|
||||
class InvenTreeHomePage extends StatefulWidget {
|
||||
|
||||
const InvenTreeHomePage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_InvenTreeHomePageState createState() => _InvenTreeHomePageState();
|
||||
}
|
||||
|
||||
|
||||
class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetProperties {
|
||||
|
||||
class _InvenTreeHomePageState extends State<InvenTreeHomePage>
|
||||
with BaseWidgetProperties {
|
||||
_InvenTreeHomePageState() : super() {
|
||||
// Load display settings
|
||||
_loadSettings();
|
||||
@ -46,7 +43,6 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
||||
_loadProfile();
|
||||
|
||||
InvenTreeAPI().registerCallback(() {
|
||||
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
// Reload the widget
|
||||
@ -70,7 +66,10 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
||||
void _showParts(BuildContext context) {
|
||||
if (!InvenTreeAPI().checkConnection()) return;
|
||||
|
||||
Navigator.push(context, MaterialPageRoute(builder: (context) => CategoryDisplayWidget(null)));
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => CategoryDisplayWidget(null)),
|
||||
);
|
||||
}
|
||||
|
||||
void _showStarredParts(BuildContext context) {
|
||||
@ -78,18 +77,17 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
||||
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => PartList({
|
||||
"starred": "true"
|
||||
})
|
||||
)
|
||||
MaterialPageRoute(builder: (context) => PartList({"starred": "true"})),
|
||||
);
|
||||
}
|
||||
|
||||
void _showStock(BuildContext context) {
|
||||
if (!InvenTreeAPI().checkConnection()) return;
|
||||
|
||||
Navigator.push(context, MaterialPageRoute(builder: (context) => LocationDisplayWidget(null)));
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => LocationDisplayWidget(null)),
|
||||
);
|
||||
}
|
||||
|
||||
void _showPurchaseOrders(BuildContext context) {
|
||||
@ -98,8 +96,8 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => PurchaseOrderListWidget(filters: {})
|
||||
)
|
||||
builder: (context) => PurchaseOrderListWidget(filters: {}),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -107,17 +105,23 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
||||
if (!InvenTreeAPI().checkConnection()) return;
|
||||
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => SalesOrderListWidget(filters: {})
|
||||
)
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => SalesOrderListWidget(filters: {}),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showSuppliers(BuildContext context) {
|
||||
if (!InvenTreeAPI().checkConnection()) return;
|
||||
|
||||
Navigator.push(context, MaterialPageRoute(builder: (context) => CompanyListWidget(L10().suppliers, {"is_supplier": "true"})));
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
CompanyListWidget(L10().suppliers, {"is_supplier": "true"}),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -131,39 +135,60 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
||||
void _showCustomers(BuildContext context) {
|
||||
if (!InvenTreeAPI().checkConnection()) return;
|
||||
|
||||
Navigator.push(context, MaterialPageRoute(builder: (context) => CompanyListWidget(L10().customers, {"is_customer": "true"})));
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
CompanyListWidget(L10().customers, {"is_customer": "true"}),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _selectProfile() {
|
||||
Navigator.push(
|
||||
context, MaterialPageRoute(builder: (context) => InvenTreeSelectServerWidget())
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => InvenTreeSelectServerWidget()),
|
||||
).then((context) {
|
||||
// Once we return
|
||||
_loadProfile();
|
||||
});
|
||||
}
|
||||
|
||||
Future <void> _loadSettings() async {
|
||||
Future<void> _loadSettings() async {
|
||||
homeShowSubscribed =
|
||||
await InvenTreeSettingsManager().getValue(
|
||||
INV_HOME_SHOW_SUBSCRIBED,
|
||||
true,
|
||||
)
|
||||
as bool;
|
||||
homeShowPo =
|
||||
await InvenTreeSettingsManager().getValue(INV_HOME_SHOW_PO, true)
|
||||
as bool;
|
||||
homeShowSo =
|
||||
await InvenTreeSettingsManager().getValue(INV_HOME_SHOW_SO, true)
|
||||
as bool;
|
||||
homeShowManufacturers =
|
||||
await InvenTreeSettingsManager().getValue(
|
||||
INV_HOME_SHOW_MANUFACTURERS,
|
||||
true,
|
||||
)
|
||||
as bool;
|
||||
homeShowCustomers =
|
||||
await InvenTreeSettingsManager().getValue(INV_HOME_SHOW_CUSTOMERS, true)
|
||||
as bool;
|
||||
homeShowSuppliers =
|
||||
await InvenTreeSettingsManager().getValue(INV_HOME_SHOW_SUPPLIERS, true)
|
||||
as bool;
|
||||
|
||||
homeShowSubscribed = await InvenTreeSettingsManager().getValue(INV_HOME_SHOW_SUBSCRIBED, true) as bool;
|
||||
homeShowPo = await InvenTreeSettingsManager().getValue(INV_HOME_SHOW_PO, true) as bool;
|
||||
homeShowSo = await InvenTreeSettingsManager().getValue(INV_HOME_SHOW_SO, true) as bool;
|
||||
homeShowManufacturers = await InvenTreeSettingsManager().getValue(INV_HOME_SHOW_MANUFACTURERS, true) as bool;
|
||||
homeShowCustomers = await InvenTreeSettingsManager().getValue(INV_HOME_SHOW_CUSTOMERS, true) as bool;
|
||||
homeShowSuppliers = await InvenTreeSettingsManager().getValue(INV_HOME_SHOW_SUPPLIERS, true) as bool;
|
||||
|
||||
setState(() {
|
||||
});
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
Future <void> _loadProfile() async {
|
||||
|
||||
Future<void> _loadProfile() async {
|
||||
_profile = await UserProfileDBManager().getSelectedProfile();
|
||||
|
||||
// A valid profile was loaded!
|
||||
if (_profile != null) {
|
||||
if (!InvenTreeAPI().isConnected() && !InvenTreeAPI().isConnecting()) {
|
||||
|
||||
// Attempt server connection
|
||||
InvenTreeAPI().connectToServer(_profile!).then((result) {
|
||||
if (mounted) {
|
||||
@ -176,8 +201,15 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
Widget _listTile(BuildContext context, String label, IconData icon, {Function()? callback, String role = "", String permission = "", Widget? trailing}) {
|
||||
|
||||
Widget _listTile(
|
||||
BuildContext context,
|
||||
String label,
|
||||
IconData icon, {
|
||||
Function()? callback,
|
||||
String role = "",
|
||||
String permission = "",
|
||||
Widget? trailing,
|
||||
}) {
|
||||
bool connected = InvenTreeAPI().isConnected();
|
||||
|
||||
bool allowed = true;
|
||||
@ -192,20 +224,15 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
||||
child: Align(
|
||||
child: ListTile(
|
||||
leading: Icon(
|
||||
icon,
|
||||
size: 32,
|
||||
color: connected && allowed ? COLOR_ACTION : Colors.grey
|
||||
),
|
||||
title: Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 20
|
||||
),
|
||||
icon,
|
||||
size: 32,
|
||||
color: connected && allowed ? COLOR_ACTION : Colors.grey,
|
||||
),
|
||||
title: Text(label, style: TextStyle(fontSize: 20)),
|
||||
trailing: trailing,
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
)
|
||||
),
|
||||
),
|
||||
onTap: () {
|
||||
if (!allowed) {
|
||||
@ -228,78 +255,89 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
||||
* Constructs a list of tiles for the main screen
|
||||
*/
|
||||
List<Widget> getListTiles(BuildContext context) {
|
||||
|
||||
List<Widget> tiles = [];
|
||||
|
||||
// Parts
|
||||
if (InvenTreePart().canView) {
|
||||
tiles.add(_listTile(
|
||||
context,
|
||||
L10().parts,
|
||||
TablerIcons.box,
|
||||
callback: () {
|
||||
_showParts(context);
|
||||
},
|
||||
));
|
||||
tiles.add(
|
||||
_listTile(
|
||||
context,
|
||||
L10().parts,
|
||||
TablerIcons.box,
|
||||
callback: () {
|
||||
_showParts(context);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Starred parts
|
||||
if (homeShowSubscribed && InvenTreePart().canView) {
|
||||
tiles.add(_listTile(
|
||||
context,
|
||||
L10().partsStarred,
|
||||
TablerIcons.bell,
|
||||
callback: () {
|
||||
_showStarredParts(context);
|
||||
}
|
||||
));
|
||||
tiles.add(
|
||||
_listTile(
|
||||
context,
|
||||
L10().partsStarred,
|
||||
TablerIcons.bell,
|
||||
callback: () {
|
||||
_showStarredParts(context);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Stock button
|
||||
if (InvenTreeStockItem().canView) {
|
||||
tiles.add(_listTile(
|
||||
tiles.add(
|
||||
_listTile(
|
||||
context,
|
||||
L10().stock,
|
||||
TablerIcons.package,
|
||||
callback: () {
|
||||
_showStock(context);
|
||||
}
|
||||
));
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Purchase orders
|
||||
if (homeShowPo && InvenTreePurchaseOrder().canView) {
|
||||
tiles.add(_listTile(
|
||||
tiles.add(
|
||||
_listTile(
|
||||
context,
|
||||
L10().purchaseOrders,
|
||||
TablerIcons.shopping_cart,
|
||||
callback: () {
|
||||
_showPurchaseOrders(context);
|
||||
}
|
||||
));
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (homeShowSo && InvenTreeSalesOrder().canView) {
|
||||
tiles.add(_listTile(
|
||||
context,
|
||||
L10().salesOrders,
|
||||
TablerIcons.truck_delivery,
|
||||
callback: () {
|
||||
_showSalesOrders(context);
|
||||
}
|
||||
));
|
||||
tiles.add(
|
||||
_listTile(
|
||||
context,
|
||||
L10().salesOrders,
|
||||
TablerIcons.truck_delivery,
|
||||
callback: () {
|
||||
_showSalesOrders(context);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Suppliers
|
||||
if (homeShowSuppliers && InvenTreePurchaseOrder().canView) {
|
||||
tiles.add(_listTile(
|
||||
tiles.add(
|
||||
_listTile(
|
||||
context,
|
||||
L10().suppliers,
|
||||
TablerIcons.building,
|
||||
callback: () {
|
||||
_showSuppliers(context);
|
||||
}
|
||||
));
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: Add these tiles back in once the features are fleshed out
|
||||
@ -320,14 +358,16 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
||||
*/
|
||||
// Customers
|
||||
if (homeShowCustomers) {
|
||||
tiles.add(_listTile(
|
||||
tiles.add(
|
||||
_listTile(
|
||||
context,
|
||||
L10().customers,
|
||||
TablerIcons.building_store,
|
||||
callback: () {
|
||||
_showCustomers(context);
|
||||
}
|
||||
));
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return tiles;
|
||||
@ -338,10 +378,10 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
||||
* display a connection status widget
|
||||
*/
|
||||
Widget _connectionStatusWidget(BuildContext context) {
|
||||
|
||||
String? serverAddress = InvenTreeAPI().serverAddress;
|
||||
bool validAddress = serverAddress != null;
|
||||
bool connecting = !InvenTreeAPI().isConnected() && InvenTreeAPI().isConnecting();
|
||||
bool connecting =
|
||||
!InvenTreeAPI().isConnected() && InvenTreeAPI().isConnecting();
|
||||
|
||||
Widget leading = Icon(TablerIcons.exclamation_circle, color: COLOR_DANGER);
|
||||
Widget trailing = Icon(TablerIcons.server, color: COLOR_ACTION);
|
||||
@ -373,8 +413,8 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
||||
trailing: trailing,
|
||||
leading: leading,
|
||||
onTap: _selectProfile,
|
||||
)
|
||||
]
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
@ -384,7 +424,6 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
||||
*/
|
||||
@override
|
||||
Widget getBody(BuildContext context) {
|
||||
|
||||
if (!InvenTreeAPI().isConnected()) {
|
||||
return _connectionStatusWidget(context);
|
||||
}
|
||||
@ -398,7 +437,7 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
||||
int hTiles = smallScreen ? 1 : 2;
|
||||
double aspect = smallScreen ? 5 : 3;
|
||||
double padding = smallScreen ? 2 : 10;
|
||||
|
||||
|
||||
return GridView.count(
|
||||
crossAxisCount: w > h ? vTiles : hTiles,
|
||||
children: getListTiles(context),
|
||||
@ -408,12 +447,10 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
||||
mainAxisSpacing: padding,
|
||||
padding: EdgeInsets.all(padding),
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
var connected = InvenTreeAPI().isConnected();
|
||||
var connecting = !connected && InvenTreeAPI().isConnecting();
|
||||
|
||||
@ -426,15 +463,19 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
TablerIcons.server,
|
||||
color: connected ? COLOR_SUCCESS : (connecting ? COLOR_PROGRESS: COLOR_DANGER),
|
||||
color: connected
|
||||
? COLOR_SUCCESS
|
||||
: (connecting ? COLOR_PROGRESS : COLOR_DANGER),
|
||||
),
|
||||
onPressed: _selectProfile,
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
drawer: InvenTreeDrawer(context),
|
||||
body: getBody(context),
|
||||
bottomNavigationBar: InvenTreeAPI().isConnected() ? buildBottomAppBar(context, homeKey) : null,
|
||||
bottomNavigationBar: InvenTreeAPI().isConnected()
|
||||
? buildBottomAppBar(context, homeKey)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user