2
0
mirror of https://github.com/inventree/inventree-app.git synced 2026-01-22 10:49:41 +00:00
Files
inventree-app/lib/widget/stock/location_list.dart
Oliver 97e4c98e46 Default filters (#755)
* Bug fix for filters

- Fix key shadowing

* Adjust default filters for stock list

* Adjust default filter values

* Add "active" filter for stock items

* Code formatting

* Add "default ordering" option

* Enable pathstring sorting

* dart format
2026-01-20 09:11:40 +11:00

102 lines
2.6 KiB
Dart

import "package:flutter/material.dart";
import "package:inventree/inventree/model.dart";
import "package:inventree/inventree/stock.dart";
import "package:inventree/widget/link_icon.dart";
import "package:inventree/widget/paginator.dart";
import "package:inventree/widget/refreshable_state.dart";
import "package:inventree/l10.dart";
class StockLocationList extends StatefulWidget {
const StockLocationList(this.filters);
final Map<String, String> filters;
@override
_StockLocationListState createState() => _StockLocationListState(filters);
}
class _StockLocationListState extends RefreshableState<StockLocationList> {
_StockLocationListState(this.filters);
final Map<String, String> filters;
@override
String getAppBarTitle() => L10().stockLocations;
@override
Widget getBody(BuildContext context) {
return PaginatedStockLocationList(filters);
}
}
class PaginatedStockLocationList extends PaginatedSearchWidget {
const PaginatedStockLocationList(
Map<String, String> filters, {
String title = "",
}) : super(filters: filters, title: title);
@override
String get searchTitle => title.isNotEmpty ? title : L10().stockLocations;
@override
_PaginatedStockLocationListState createState() =>
_PaginatedStockLocationListState();
}
class _PaginatedStockLocationListState
extends PaginatedSearchState<PaginatedStockLocationList> {
_PaginatedStockLocationListState() : super();
@override
Map<String, String> get orderingOptions => {
"name": L10().name,
"pathstring": L10().path,
"items": L10().stockItems,
"level": L10().level,
};
@override
String get defaultOrdering => "pathstring";
@override
Map<String, Map<String, dynamic>> get filterOptions => {
"cascade": {
"label": L10().includeSublocations,
"help_text": L10().includeSublocationsDetail,
"tristate": false,
},
};
@override
Future<InvenTreePageResponse?> requestPage(
int limit,
int offset,
Map<String, String> params,
) async {
final page = await InvenTreeStockLocation().listPaginated(
limit,
offset,
filters: params,
);
return page;
}
@override
Widget buildItem(BuildContext context, InvenTreeModel model) {
InvenTreeStockLocation location = model as InvenTreeStockLocation;
return ListTile(
title: Text(location.name),
subtitle: Text(location.pathstring),
trailing: LargeText("${location.itemcount}", size: 14),
leading: location.customIcon == null ? null : Icon(location.customIcon),
onTap: () {
location.goToDetailPage(context);
},
);
}
}