2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-27 21:16:48 +00:00

More linting again

This commit is contained in:
Oliver 2021-09-28 21:34:11 +10:00
parent 77bac9af36
commit be36811cb3
20 changed files with 68 additions and 75 deletions

View File

@ -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

View File

@ -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<String> errorMessages() {
@ -660,7 +660,7 @@ Future<void> launchApiForm(BuildContext context, String title, String url, Map<S
class APIFormWidget extends StatefulWidget {
APIFormWidget(
const APIFormWidget(
this.title,
this.url,
this.fields,
@ -685,7 +685,7 @@ class APIFormWidget extends StatefulWidget {
final List<APIFormField> fields;
Function(Map<String, dynamic>)? onSuccess;
final Function(Map<String, dynamic>)? onSuccess;
@override
_APIFormWidgetState createState() => _APIFormWidgetState(title, url, fields, method, onSuccess, fileField);

View File

@ -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<String, dynamic> jsondata = {};
// Accessor for the API
var api = InvenTreeAPI();
InvenTreeAPI api = InvenTreeAPI();
int get pk => (jsondata["pk"] ?? -1) as int;

View File

@ -42,7 +42,7 @@ class InvenTreePartCategory extends InvenTreeModel {
// TODO - Drive the refactor tractor through this
List<String> psplit = pathstring.split("/");
if (psplit.length > 0) {
if (psplit.isNotEmpty) {
psplit.removeLast();
}

View File

@ -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<String, dynamic> formFields() {
@ -549,7 +549,7 @@ class InvenTreeStockLocation extends InvenTreeModel {
// TODO - Drive the refactor tractor through this
List<String> psplit = pathstring.split("/");
if (psplit.length > 0) {
if (psplit.isNotEmpty) {
psplit.removeLast();
}

View File

@ -79,24 +79,6 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
}
}
Future <void> _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<InvenTreeLoginSettingsWidget> {
List<Widget> 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<InvenTreeLoginSettingsWidget> {
class ProfileEditWidget extends StatefulWidget {
ProfileEditWidget(this.profile) : super();
const ProfileEditWidget(this.profile) : super();
UserProfile? profile;
final UserProfile? profile;
@override
_ProfileEditState createState() => _ProfileEditState(profile);

View File

@ -198,7 +198,7 @@ class _CategoryDisplayState extends RefreshableState<CategoryDisplayWidget> {
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<CategoryDisplayWidget> {
}
}
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<String, String> filters;
Function(int)? onTotalChanged;
final Function(int)? onTotalChanged;
@override
_PaginatedPartListState createState() => _PaginatedPartListState(filters, onTotalChanged);

View File

@ -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<String, String> filters;
final Map<String, String> filters;
@override
_CompanyListWidgetState createState() => _CompanyListWidgetState(title, filters);
@ -49,11 +49,11 @@ class _CompanyListWidgetState extends RefreshableState<CompanyListWidget> {
class PaginatedCompanyList extends StatefulWidget {
PaginatedCompanyList(this.filters, {this.onTotalChanged});
const PaginatedCompanyList(this.filters, {this.onTotalChanged});
final Map<String, String> filters;
Function(int)? onTotalChanged;
final Function(int)? onTotalChanged;
@override
_CompanyListState createState() => _CompanyListState(filters, onTotalChanged);

View File

@ -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,

View File

@ -313,13 +313,13 @@ List<Widget> 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(

View File

@ -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) {

View File

@ -123,7 +123,7 @@ class _PartAttachmentDisplayState extends RefreshableState<PartAttachmentsWidget
));
}
if (tiles.length == 0) {
if (tiles.isEmpty) {
tiles.add(ListTile(
title: Text(L10().attachmentNone),
subtitle: Text(

View File

@ -17,7 +17,7 @@ import "package:inventree/widget/refreshable_state.dart";
import "package:inventree/widget/part_image_widget.dart";
import "package:inventree/widget/stock_detail.dart";
import "pcakage:inventree/widget/location_display.dart";
import "package:inventree/widget/location_display.dart";
class PartDetailWidget extends StatefulWidget {
@ -442,20 +442,22 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
);
// 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<PartDetailWidget> {
)
);
}
*/
return tiles;
}

View File

@ -43,11 +43,11 @@ class _PurchaseOrderListWidgetState extends RefreshableState<PurchaseOrderListWi
class _PaginatedPurchaseOrderList extends StatefulWidget {
_PaginatedPurchaseOrderList(this.filters, {this.onTotalChanged});
const _PaginatedPurchaseOrderList(this.filters, {this.onTotalChanged});
final Map<String, String> filters;
Function(int)? onTotalChanged;
final Function(int)? onTotalChanged;
@override
_PaginatedPurchaseOrderListState createState() => _PaginatedPurchaseOrderListState(filters, onTotalChanged);

View File

@ -9,7 +9,7 @@ abstract class RefreshableState<T extends StatefulWidget> extends State<T> {
final refreshableKey = GlobalKey<ScaffoldState>();
// 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;

View File

@ -86,7 +86,7 @@ class PartSearchDelegate extends SearchDelegate<InvenTreePart?> {
showSnackIcon(
"${partResults.length} ${L10().results}",
success: partResults.length > 0,
success: partResults.isNotEmpty,
icon: FontAwesomeIcons.pollH,
);
@ -161,7 +161,7 @@ class PartSearchDelegate extends SearchDelegate<InvenTreePart?> {
search(context);
if (query.length == 0) {
if (query.isEmpty) {
return ListTile(
title: Text(L10().queryEnter)
);
@ -174,7 +174,7 @@ class PartSearchDelegate extends SearchDelegate<InvenTreePart?> {
);
}
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<InvenTreeStockItem?> {
showSnackIcon(
"${itemResults.length} ${L10().results}",
success: itemResults.length > 0,
success: itemResults.isNotEmpty,
icon: FontAwesomeIcons.pollH,
);
@ -349,7 +349,7 @@ class StockSearchDelegate extends SearchDelegate<InvenTreeStockItem?> {
search(context);
if (query.length == 0) {
if (query.isEmpty) {
return ListTile(
title: Text(L10().queryEnter)
);
@ -362,7 +362,7 @@ class StockSearchDelegate extends SearchDelegate<InvenTreeStockItem?> {
);
}
if (itemResults.length == 0) {
if (itemResults.isEmpty) {
return ListTile(
title: Text(L10().noResults),
subtitle: Text(L10().queryNoResults + " '${query}'")

View File

@ -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;

View File

@ -22,7 +22,7 @@ class Spinner extends StatefulWidget {
}
class _SpinnerState extends State<Spinner> with SingleTickerProviderStateMixin {
AnimationController? _controller;
late AnimationController? _controller;
Widget? _child;
@override

View File

@ -71,7 +71,7 @@ class _StarredPartState extends RefreshableState<StarredPartWidget> {
return progressIndicator();
}
if (starredParts.length == 0) {
if (starredParts.isEmpty) {
return ListView(
children: [
ListTile(

View File

@ -142,7 +142,7 @@ class _StockItemTestResultDisplayState extends RefreshableState<StockItemTestRes
var results = getTestResults();
if (results.length == 0) {
if (results.isEmpty) {
tiles.add(ListTile(
title: Text(L10().testResultNone),
subtitle: Text(L10().testResultNoneDetail),