2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-06-12 02:05:29 +00:00

Many many changes for null-safety support

This commit is contained in:
Oliver
2021-07-09 23:56:38 +10:00
parent 2988716bf3
commit d3eec6a79e
30 changed files with 563 additions and 456 deletions

View File

@ -20,11 +20,11 @@ import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
class LocationDisplayWidget extends StatefulWidget {
LocationDisplayWidget(this.location, {Key key}) : super(key: key);
LocationDisplayWidget(this.location, {Key? key}) : super(key: key);
final InvenTreeStockLocation location;
final InvenTreeStockLocation? location;
final String title = "Location";
final String title = L10().stockLocation;
@override
_LocationDisplayState createState() => _LocationDisplayState(location);
@ -32,12 +32,12 @@ class LocationDisplayWidget extends StatefulWidget {
class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
final InvenTreeStockLocation location;
final InvenTreeStockLocation? location;
final _editLocationKey = GlobalKey<FormState>();
@override
String getAppBarTitle(BuildContext context) { return "Stock Location"; }
String getAppBarTitle(BuildContext context) { return L10().stockLocation; }
@override
List<Widget> getAppBarActions(BuildContext context) {
@ -80,12 +80,16 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
void _editLocation(Map<String, String> values) async {
final bool result = await location.update(context, values: values);
bool result = false;
showSnackIcon(
result ? "Location edited" : "Location editing failed",
success: result
);
if (location != null) {
result = await location!.update(values: values);
showSnackIcon(
result ? "Location edited" : "Location editing failed",
success: result
);
}
refresh();
}
@ -95,6 +99,10 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
var _name;
var _description;
if (location == null) {
return;
}
showFormDialog(L10().editLocation,
key: _editLocationKey,
callback: () {
@ -106,12 +114,12 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
fields: <Widget> [
StringField(
label: L10().name,
initial: location.name,
initial: location?.name ?? '',
onSaved: (value) => _name = value,
),
StringField(
label: L10().description,
initial: location.description,
initial: location?.description ?? '',
onSaved: (value) => _description = value,
)
]
@ -120,7 +128,7 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
_LocationDisplayState(this.location) {}
List<InvenTreeStockLocation> _sublocations = List<InvenTreeStockLocation>();
List<InvenTreeStockLocation> _sublocations = List<InvenTreeStockLocation>.empty();
String _locationFilter = '';
@ -139,17 +147,17 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
}
@override
Future<void> request(BuildContext context) async {
Future<void> request() async {
int pk = location?.pk ?? -1;
// Reload location information
if (location != null) {
await location.reload(context);
await location?.reload();
}
// Request a list of sub-locations under this one
await InvenTreeStockLocation().list(context, filters: {"parent": "$pk"}).then((var locs) {
await InvenTreeStockLocation().list(filters: {"parent": "$pk"}).then((var locs) {
_sublocations.clear();
for (var loc in locs) {
@ -173,8 +181,8 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
List<Widget> children = [
ListTile(
title: Text("${location.name}"),
subtitle: Text("${location.description}"),
title: Text("${location!.name}"),
subtitle: Text("${location!.description}"),
),
];
@ -182,13 +190,17 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
children.add(
ListTile(
title: Text(L10().parentCategory),
subtitle: Text("${location.parentpathstring}"),
subtitle: Text("${location!.parentpathstring}"),
leading: FaIcon(FontAwesomeIcons.levelUpAlt),
onTap: () {
if (location.parentId < 0) {
int parent = location?.parentId ?? -1;
if (parent < 0) {
Navigator.push(context, MaterialPageRoute(builder: (context) => LocationDisplayWidget(null)));
} else {
InvenTreeStockLocation().get(context, location.parentId).then((var loc) {
InvenTreeStockLocation().get(parent).then((var loc) {
if (loc is InvenTreeStockLocation) {
Navigator.push(context, MaterialPageRoute(builder: (context) => LocationDisplayWidget(loc)));
}
@ -238,7 +250,7 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
Map<String, String> filters = {};
if (location != null) {
filters["location"] = "${location.pk}";
filters["location"] = "${location!.pk}";
}
switch (index) {
@ -256,7 +268,7 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
).toList()
);
default:
return null;
return ListView();
}
}
@ -297,7 +309,7 @@ List<Widget> detailTiles() {
List<Widget> tiles = [];
tiles.add(locationDescriptionCard(includeActions: false));
if (location != null) {
// Stock adjustment actions
if (InvenTreeAPI().checkPermission('stock', 'change')) {
@ -308,14 +320,19 @@ List<Widget> detailTiles() {
leading: FaIcon(FontAwesomeIcons.exchangeAlt),
trailing: FaIcon(FontAwesomeIcons.qrcode),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) =>
InvenTreeQRView(
StockLocationScanInItemsHandler(location)))
).then((context) {
refresh();
});
var _loc = location;
if (_loc != null) {
Navigator.push(
context,
MaterialPageRoute(builder: (context) =>
InvenTreeQRView(
StockLocationScanInItemsHandler(_loc)))
).then((context) {
refresh();
});
}
},
)
);
@ -361,7 +378,7 @@ class SublocationList extends StatelessWidget {
void _openLocation(BuildContext context, int pk) {
InvenTreeStockLocation().get(context, pk).then((var loc) {
InvenTreeStockLocation().get(pk).then((var loc) {
if (loc is InvenTreeStockLocation) {
Navigator.push(context, MaterialPageRoute(builder: (context) => LocationDisplayWidget(loc)));
@ -452,26 +469,32 @@ class _PaginatedStockListState extends State<PaginatedStockList> {
params["cascade"] = "${cascade}";
final page = await InvenTreeStockItem().listPaginated(_pageSize, pageKey, filters: params);
final isLastPage = page.length < _pageSize;
int pageLength = page?.length ?? 0;
int pageCount = page?.count ?? 0;
final isLastPage = pageLength < _pageSize;
// Construct a list of stock item objects
List<InvenTreeStockItem> items = [];
for (var result in page.results) {
if (result is InvenTreeStockItem) {
items.add(result);
if (page != null) {
for (var result in page.results) {
if (result is InvenTreeStockItem) {
items.add(result);
}
}
}
if (isLastPage) {
_pagingController.appendLastPage(items);
} else {
final int nextPageKey = pageKey + page.length;
final int nextPageKey = pageKey + pageLength;
_pagingController.appendPage(items, nextPageKey);
}
setState(() {
resultCount = page.count;
resultCount = pageCount;
});
} catch (error) {
@ -480,7 +503,7 @@ class _PaginatedStockListState extends State<PaginatedStockList> {
}
void _openItem(BuildContext context, int pk) {
InvenTreeStockItem().get(context, pk).then((var item) {
InvenTreeStockItem().get(pk).then((var item) {
if (item is InvenTreeStockItem) {
Navigator.push(context, MaterialPageRoute(builder: (context) => StockDetailWidget(item)));
}