diff --git a/analysis_options.yaml b/analysis_options.yaml index 07b40c28..418cc57b 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -35,6 +35,8 @@ linter: unnecessary_string_interpolations: false + prefer_interpolation_to_compose_strings: false + no_logic_in_create_state: false parameter_assignments: false @@ -59,3 +61,5 @@ linter: # Blindly follow the Flutter code style, which prefers types everywhere always_specify_types: false + + avoid_unnecessary_containers: false diff --git a/lib/api_form.dart b/lib/api_form.dart index 70971a13..f134a806 100644 --- a/lib/api_form.dart +++ b/lib/api_form.dart @@ -55,7 +55,7 @@ class APIFormField { bool get multiline => (data["multiline"] ?? false) as bool; // Get the "value" as a string (look for "default" if not available) - dynamic get value => (data["value"] ?? data["default"]); + dynamic get value => data["value"] ?? data["default"]; // Get the "default" as a string dynamic get defaultValue => data["default"]; @@ -92,7 +92,7 @@ class APIFormField { } - bool hasErrors() => errorMessages().length > 0; + bool hasErrors() => errorMessages().isNotEmpty; // Return the error message associated with this field List errorMessages() { @@ -660,7 +660,7 @@ Future launchApiForm(BuildContext context, String title, String url, Map fields; - Function(Map)? onSuccess; + final Function(Map)? onSuccess; @override _APIFormWidgetState createState() => _APIFormWidgetState(title, url, fields, method, onSuccess, fileField); diff --git a/lib/inventree/model.dart b/lib/inventree/model.dart index bd1517ec..4eb234ec 100644 --- a/lib/inventree/model.dart +++ b/lib/inventree/model.dart @@ -49,7 +49,7 @@ class InvenTreeModel { // Override the web URL for each subclass // Note: If the WEB_URL is the same (except for /api/) as URL then just leave blank - String WEB_URL = ""; + String get WEB_URL => ""; String get webUrl { @@ -118,7 +118,7 @@ class InvenTreeModel { Map jsondata = {}; // Accessor for the API - var api = InvenTreeAPI(); + InvenTreeAPI api = InvenTreeAPI(); int get pk => (jsondata["pk"] ?? -1) as int; diff --git a/lib/inventree/part.dart b/lib/inventree/part.dart index 804615e6..16b2562d 100644 --- a/lib/inventree/part.dart +++ b/lib/inventree/part.dart @@ -42,7 +42,7 @@ class InvenTreePartCategory extends InvenTreeModel { // TODO - Drive the refactor tractor through this List psplit = pathstring.split("/"); - if (psplit.length > 0) { + if (psplit.isNotEmpty) { psplit.removeLast(); } diff --git a/lib/inventree/stock.dart b/lib/inventree/stock.dart index cbfe7142..82c37711 100644 --- a/lib/inventree/stock.dart +++ b/lib/inventree/stock.dart @@ -114,7 +114,7 @@ class InvenTreeStockItem extends InvenTreeModel { String get URL => "stock/"; @override - String WEB_URL = "stock/item/"; + String get WEB_URL => "stock/item/"; @override Map formFields() { @@ -549,7 +549,7 @@ class InvenTreeStockLocation extends InvenTreeModel { // TODO - Drive the refactor tractor through this List psplit = pathstring.split("/"); - if (psplit.length > 0) { + if (psplit.isNotEmpty) { psplit.removeLast(); } diff --git a/lib/settings/login.dart b/lib/settings/login.dart index 32cdc35c..086be345 100644 --- a/lib/settings/login.dart +++ b/lib/settings/login.dart @@ -79,24 +79,6 @@ class _InvenTreeLoginSettingsState extends State { } } - Future _updateProfile(UserProfile? profile) async { - - if (profile == null) { - return; - } - - _reload(); - - if (InvenTreeAPI().isConnected() && InvenTreeAPI().profile != null && profile.key == (InvenTreeAPI().profile?.key ?? "")) { - // Attempt server login (this will load the newly selected profile - - InvenTreeAPI().connectToServer().then((result) { - _reload(); - }); - } - } - - Widget? _getProfileIcon(UserProfile profile) { // Not selected? No icon for you! @@ -134,7 +116,7 @@ class _InvenTreeLoginSettingsState extends State { List children = []; - if (profiles.length > 0) { + if (profiles.isNotEmpty) { for (int idx = 0; idx < profiles.length; idx++) { UserProfile profile = profiles[idx]; @@ -237,9 +219,9 @@ class _InvenTreeLoginSettingsState extends State { class ProfileEditWidget extends StatefulWidget { - ProfileEditWidget(this.profile) : super(); + const ProfileEditWidget(this.profile) : super(); - UserProfile? profile; + final UserProfile? profile; @override _ProfileEditState createState() => _ProfileEditState(profile); diff --git a/lib/widget/category_display.dart b/lib/widget/category_display.dart index 80ce8605..3fa0d7d5 100644 --- a/lib/widget/category_display.dart +++ b/lib/widget/category_display.dart @@ -198,7 +198,7 @@ class _CategoryDisplayState extends RefreshableState { if (loading) { tiles.add(progressIndicator()); - } else if (_subcategories.length == 0) { + } else if (_subcategories.isEmpty) { tiles.add(ListTile( title: Text(L10().noSubcategories), subtitle: Text( @@ -301,7 +301,7 @@ class _CategoryDisplayState extends RefreshableState { } } - if (tiles.length == 0) { + if (tiles.isEmpty) { tiles.add( ListTile( title: Text( @@ -397,11 +397,11 @@ class SubcategoryList extends StatelessWidget { class PaginatedPartList extends StatefulWidget { - PaginatedPartList(this.filters, {this.onTotalChanged}); + const PaginatedPartList(this.filters, {this.onTotalChanged}); final Map filters; - Function(int)? onTotalChanged; + final Function(int)? onTotalChanged; @override _PaginatedPartListState createState() => _PaginatedPartListState(filters, onTotalChanged); diff --git a/lib/widget/company_list.dart b/lib/widget/company_list.dart index acf9b3f8..948cf25a 100644 --- a/lib/widget/company_list.dart +++ b/lib/widget/company_list.dart @@ -15,11 +15,11 @@ import "package:inventree/l10.dart"; class CompanyListWidget extends StatefulWidget { - CompanyListWidget(this.title, this.filters, {Key? key}) : super(key: key); + const CompanyListWidget(this.title, this.filters, {Key? key}) : super(key: key); - String title; + final String title; - Map filters; + final Map filters; @override _CompanyListWidgetState createState() => _CompanyListWidgetState(title, filters); @@ -49,11 +49,11 @@ class _CompanyListWidgetState extends RefreshableState { class PaginatedCompanyList extends StatefulWidget { - PaginatedCompanyList(this.filters, {this.onTotalChanged}); + const PaginatedCompanyList(this.filters, {this.onTotalChanged}); final Map filters; - Function(int)? onTotalChanged; + final Function(int)? onTotalChanged; @override _CompanyListState createState() => _CompanyListState(filters, onTotalChanged); diff --git a/lib/widget/fields.dart b/lib/widget/fields.dart index 7c6a74d6..eb5b7b1a 100644 --- a/lib/widget/fields.dart +++ b/lib/widget/fields.dart @@ -194,7 +194,7 @@ class StringField extends TextFormField { */ class QuantityField extends TextFormField { - QuantityField({String label = "", String hint = "", String initial = "", double? max, TextEditingController? controller}) : + QuantityField({String label = "", String hint = "", double? max, TextEditingController? controller}) : super( decoration: InputDecoration( labelText: label, diff --git a/lib/widget/location_display.dart b/lib/widget/location_display.dart index c2670e38..145e9982 100644 --- a/lib/widget/location_display.dart +++ b/lib/widget/location_display.dart @@ -313,13 +313,13 @@ List detailTiles() { L10().sublocations, style: TextStyle(fontWeight: FontWeight.bold), ), - trailing: sublocations.length > 0 ? Text("${sublocations.length}") : null, + trailing: sublocations.isNotEmpty ? Text("${sublocations.length}") : null, ), ]; if (loading) { tiles.add(progressIndicator()); - } else if (_sublocations.length > 0) { + } else if (_sublocations.isNotEmpty) { tiles.add(SublocationList(_sublocations)); } else { tiles.add(ListTile( diff --git a/lib/widget/paginator.dart b/lib/widget/paginator.dart index c5482e35..6d5eba0c 100644 --- a/lib/widget/paginator.dart +++ b/lib/widget/paginator.dart @@ -5,13 +5,13 @@ import "package:inventree/l10.dart"; class PaginatedSearchWidget extends StatelessWidget { - PaginatedSearchWidget(this.controller, this.onChanged, this.results); + const PaginatedSearchWidget(this.controller, this.onChanged, this.results); - Function onChanged; + final Function onChanged; - int results = 0; + final int results; - TextEditingController controller; + final TextEditingController controller; @override Widget build(BuildContext context) { diff --git a/lib/widget/part_attachments_widget.dart b/lib/widget/part_attachments_widget.dart index 3af0e004..2e14141f 100644 --- a/lib/widget/part_attachments_widget.dart +++ b/lib/widget/part_attachments_widget.dart @@ -123,7 +123,7 @@ class _PartAttachmentDisplayState extends RefreshableState { ); // TODO - Add this action back in once implemented - if (false) { - tiles.add( - ListTile( - title: Text(L10().barcodeScanItem), - leading: FaIcon(FontAwesomeIcons.box), - trailing: FaIcon(FontAwesomeIcons.qrcode), - onTap: () { - // TODO - }, - ), - ); - } - - if (false && !part.isActive && InvenTreeAPI().checkPermission("part", "delete")) { + /* + tiles.add( + ListTile( + title: Text(L10().barcodeScanItem), + leading: FaIcon(FontAwesomeIcons.box), + trailing: FaIcon(FontAwesomeIcons.qrcode), + onTap: () { + // TODO + }, + ), + ); + */ + + /* + // TODO: Implement part deletion + if (!part.isActive && InvenTreeAPI().checkPermission("part", "delete")) { tiles.add( ListTile( title: Text(L10().deletePart), @@ -467,6 +469,7 @@ class _PartDisplayState extends RefreshableState { ) ); } + */ return tiles; } diff --git a/lib/widget/purchase_order_list.dart b/lib/widget/purchase_order_list.dart index d05010e4..67db6512 100644 --- a/lib/widget/purchase_order_list.dart +++ b/lib/widget/purchase_order_list.dart @@ -43,11 +43,11 @@ class _PurchaseOrderListWidgetState extends RefreshableState filters; - Function(int)? onTotalChanged; + final Function(int)? onTotalChanged; @override _PaginatedPurchaseOrderListState createState() => _PaginatedPurchaseOrderListState(filters, onTotalChanged); diff --git a/lib/widget/refreshable_state.dart b/lib/widget/refreshable_state.dart index 77508f3b..fb1e3559 100644 --- a/lib/widget/refreshable_state.dart +++ b/lib/widget/refreshable_state.dart @@ -9,7 +9,7 @@ abstract class RefreshableState extends State { final refreshableKey = GlobalKey(); // Storage for context once "Build" is called - BuildContext? _context; + late BuildContext? _context; // Current tab index (used for widgets which display bottom tabs) int tabIndex = 0; diff --git a/lib/widget/search.dart b/lib/widget/search.dart index a6a73537..4f2cbd23 100644 --- a/lib/widget/search.dart +++ b/lib/widget/search.dart @@ -86,7 +86,7 @@ class PartSearchDelegate extends SearchDelegate { showSnackIcon( "${partResults.length} ${L10().results}", - success: partResults.length > 0, + success: partResults.isNotEmpty, icon: FontAwesomeIcons.pollH, ); @@ -161,7 +161,7 @@ class PartSearchDelegate extends SearchDelegate { search(context); - if (query.length == 0) { + if (query.isEmpty) { return ListTile( title: Text(L10().queryEnter) ); @@ -174,7 +174,7 @@ class PartSearchDelegate extends SearchDelegate { ); } - if (partResults.length == 0) { + if (partResults.isEmpty) { return ListTile( title: Text(L10().noResults), subtitle: Text(L10().queryNoResults + " '${query}'") @@ -275,7 +275,7 @@ class StockSearchDelegate extends SearchDelegate { showSnackIcon( "${itemResults.length} ${L10().results}", - success: itemResults.length > 0, + success: itemResults.isNotEmpty, icon: FontAwesomeIcons.pollH, ); @@ -349,7 +349,7 @@ class StockSearchDelegate extends SearchDelegate { search(context); - if (query.length == 0) { + if (query.isEmpty) { return ListTile( title: Text(L10().queryEnter) ); @@ -362,7 +362,7 @@ class StockSearchDelegate extends SearchDelegate { ); } - if (itemResults.length == 0) { + if (itemResults.isEmpty) { return ListTile( title: Text(L10().noResults), subtitle: Text(L10().queryNoResults + " '${query}'") diff --git a/lib/widget/snacks.dart b/lib/widget/snacks.dart index 6a33cee1..fdbeb1c0 100644 --- a/lib/widget/snacks.dart +++ b/lib/widget/snacks.dart @@ -17,7 +17,11 @@ import "package:inventree/l10.dart"; void showSnackIcon(String text, {IconData? icon, Function()? onAction, bool? success, String? actionText}) { - OneContext().hideCurrentSnackBar(); + BuildContext? context = OneContext().context; + + if (context != null) { + ScaffoldMessenger.of(context).hideCurrentSnackBar(); + } Color backgroundColor = Colors.deepOrange; diff --git a/lib/widget/spinner.dart b/lib/widget/spinner.dart index d5723ccf..faebe750 100644 --- a/lib/widget/spinner.dart +++ b/lib/widget/spinner.dart @@ -22,7 +22,7 @@ class Spinner extends StatefulWidget { } class _SpinnerState extends State with SingleTickerProviderStateMixin { - AnimationController? _controller; + late AnimationController? _controller; Widget? _child; @override diff --git a/lib/widget/starred_parts.dart b/lib/widget/starred_parts.dart index 6d15d952..fbb33936 100644 --- a/lib/widget/starred_parts.dart +++ b/lib/widget/starred_parts.dart @@ -71,7 +71,7 @@ class _StarredPartState extends RefreshableState { return progressIndicator(); } - if (starredParts.length == 0) { + if (starredParts.isEmpty) { return ListView( children: [ ListTile( diff --git a/lib/widget/stock_item_test_results.dart b/lib/widget/stock_item_test_results.dart index 27556e50..d7d3a7cf 100644 --- a/lib/widget/stock_item_test_results.dart +++ b/lib/widget/stock_item_test_results.dart @@ -142,7 +142,7 @@ class _StockItemTestResultDisplayState extends RefreshableState