mirror of
https://github.com/inventree/inventree-app.git
synced 2025-05-02 07:26:50 +00:00
Display a list of companies, with filtering
This commit is contained in:
parent
aa8a3602e8
commit
d2168b2cb9
@ -10,6 +10,8 @@ class InvenTreeCompany extends InvenTreeModel {
|
||||
|
||||
InvenTreeCompany() : super();
|
||||
|
||||
String get image => jsondata['image'] ?? '';
|
||||
|
||||
InvenTreeCompany.fromJson(Map<String, dynamic> json) : super.fromJson(json) {
|
||||
// TODO
|
||||
}
|
||||
|
@ -172,7 +172,16 @@ class InvenTreeModel {
|
||||
// TODO - Define a 'save' / 'update' function
|
||||
|
||||
// Override this function for each sub-class
|
||||
bool matchAgainstString(String filter) => false;
|
||||
bool matchAgainstString(String filter) {
|
||||
// Default implementation matches name and description
|
||||
// Override this behaviour in sub-class if required
|
||||
|
||||
if (name.toLowerCase().contains(filter)) return true;
|
||||
if (description.toLowerCase().contains(filter)) return true;
|
||||
|
||||
// No matches!
|
||||
return false;
|
||||
}
|
||||
|
||||
// Filter this item against a list of provided filters
|
||||
// Each filter must be matched
|
||||
|
@ -195,13 +195,4 @@ class InvenTreeStockLocation extends InvenTreeModel {
|
||||
return loc;
|
||||
}
|
||||
|
||||
@override
|
||||
bool matchAgainstString(String filter) {
|
||||
|
||||
if (name.toLowerCase().contains(filter)) return true;
|
||||
|
||||
if (description.toLowerCase().contains(filter)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ import 'dart:async';
|
||||
|
||||
import 'package:InvenTree/inventree/stock.dart';
|
||||
import 'package:InvenTree/widget/category_display.dart';
|
||||
import 'package:InvenTree/widget/company_list.dart';
|
||||
import 'package:InvenTree/widget/location_display.dart';
|
||||
import 'package:InvenTree/widget/drawer.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
@ -207,12 +208,17 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
}
|
||||
|
||||
void _stock() {
|
||||
|
||||
if (!InvenTreeAPI().checkConnection(context)) return;
|
||||
|
||||
Navigator.push(context, MaterialPageRoute(builder: (context) => LocationDisplayWidget(null)));
|
||||
}
|
||||
|
||||
void _suppliers() {
|
||||
if (!InvenTreeAPI().checkConnection(context)) return;
|
||||
|
||||
Navigator.push(context, MaterialPageRoute(builder: (context) => CompanyListWidget()));
|
||||
}
|
||||
|
||||
void _unsupported() {
|
||||
showDialog(
|
||||
context: context,
|
||||
@ -311,7 +317,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
IconButton(
|
||||
icon: new FaIcon(FontAwesomeIcons.industry),
|
||||
tooltip: 'Suppliers',
|
||||
onPressed: _unsupported,
|
||||
onPressed: _suppliers,
|
||||
),
|
||||
Text("Suppliers"),
|
||||
]
|
||||
|
106
lib/widget/company_list.dart
Normal file
106
lib/widget/company_list.dart
Normal file
@ -0,0 +1,106 @@
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:InvenTree/api.dart';
|
||||
import 'package:InvenTree/inventree/company.dart';
|
||||
import 'package:InvenTree/widget/drawer.dart';
|
||||
|
||||
class CompanyListWidget extends StatefulWidget {
|
||||
|
||||
@override
|
||||
_CompanyListState createState() => _CompanyListState();
|
||||
|
||||
}
|
||||
|
||||
|
||||
class _CompanyListState extends State<CompanyListWidget> {
|
||||
|
||||
var _companies = new List<InvenTreeCompany>();
|
||||
|
||||
var _filteredCompanies = new List<InvenTreeCompany>();
|
||||
|
||||
var _title = "Companies";
|
||||
|
||||
_CompanyListState() {
|
||||
_requestData();
|
||||
}
|
||||
|
||||
void _requestData() {
|
||||
|
||||
InvenTreeCompany().list().then((var companies) {
|
||||
|
||||
_companies.clear();
|
||||
|
||||
for (var c in companies) {
|
||||
if (c is InvenTreeCompany) {
|
||||
_companies.add(c);
|
||||
}
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_filterResults("");
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
void _filterResults(String text) {
|
||||
|
||||
if (text.isEmpty) {
|
||||
_filteredCompanies = _companies;
|
||||
} else {
|
||||
_filteredCompanies = _companies.where((c) => c.filter(text)).toList();
|
||||
}
|
||||
}
|
||||
|
||||
Widget _showCompany(BuildContext context, int index) {
|
||||
|
||||
InvenTreeCompany company = _filteredCompanies[index];
|
||||
|
||||
return ListTile(
|
||||
title: Text("${company.name}"),
|
||||
subtitle: Text("${company.description}"),
|
||||
leading: Image(
|
||||
image: InvenTreeAPI().getImage(company.image),
|
||||
width: 40,
|
||||
),
|
||||
onTap: () {
|
||||
if (company.pk > 0) {
|
||||
InvenTreeCompany().get(company.pk).then((var c) {
|
||||
print("Retrieved company: ${c.name}");
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("$_title"),
|
||||
),
|
||||
drawer: new InvenTreeDrawer(context),
|
||||
body: ListView(
|
||||
children: <Widget>[
|
||||
TextField(
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Filter results',
|
||||
),
|
||||
onChanged: (String text) {
|
||||
setState(() {
|
||||
_filterResults(text);
|
||||
});
|
||||
},
|
||||
),
|
||||
ListView.builder(
|
||||
shrinkWrap: true,
|
||||
physics: ClampingScrollPhysics(),
|
||||
itemBuilder: _showCompany, itemCount: _filteredCompanies.length)
|
||||
],
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user