mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 13:36:50 +00:00
Add "QuantityField"
Juicy juicy refactoring
This commit is contained in:
parent
51a877e8d7
commit
a7d11faec8
@ -142,6 +142,16 @@ class InvenTreeStockItem extends InvenTreeModel {
|
|||||||
return loc;
|
return loc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String get locationPathString {
|
||||||
|
String path = '';
|
||||||
|
|
||||||
|
if (jsondata.containsKey('location_detail')) {
|
||||||
|
path = jsondata['location_detail']['pathstring'] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
String get displayQuantity {
|
String get displayQuantity {
|
||||||
// Display either quantity or serial number!
|
// Display either quantity or serial number!
|
||||||
|
|
||||||
|
26
lib/widget/fields.dart
Normal file
26
lib/widget/fields.dart
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class QuantityField extends TextFormField {
|
||||||
|
|
||||||
|
QuantityField({String label = "", String hint = "", double max = null, TextEditingController controller}) :
|
||||||
|
super(
|
||||||
|
decoration: InputDecoration(
|
||||||
|
labelText: label,
|
||||||
|
hintText: hint,
|
||||||
|
),
|
||||||
|
controller: controller,
|
||||||
|
keyboardType: TextInputType.numberWithOptions(signed: false, decimal: true),
|
||||||
|
validator: (value) {
|
||||||
|
if (value.isEmpty) return "Quantity is empty";
|
||||||
|
|
||||||
|
double quantity = double.tryParse(value);
|
||||||
|
|
||||||
|
if (quantity == null) return "Invalid quantity";
|
||||||
|
if (quantity <= 0) return "Quantity must be positive";
|
||||||
|
if ((max != null) && (quantity > max)) return "Quantity must not exceed ${max}";
|
||||||
|
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
@ -204,6 +204,10 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
icon: FaIcon(FontAwesomeIcons.infoCircle),
|
icon: FaIcon(FontAwesomeIcons.infoCircle),
|
||||||
title: Text("Details"),
|
title: Text("Details"),
|
||||||
),
|
),
|
||||||
|
BottomNavigationBarItem(
|
||||||
|
icon: FaIcon(FontAwesomeIcons.thList),
|
||||||
|
title: Text("BOM"),
|
||||||
|
),
|
||||||
BottomNavigationBarItem(
|
BottomNavigationBarItem(
|
||||||
icon: FaIcon(FontAwesomeIcons.boxes),
|
icon: FaIcon(FontAwesomeIcons.boxes),
|
||||||
title: Text("Stock"),
|
title: Text("Stock"),
|
||||||
|
@ -54,6 +54,10 @@ abstract class RefreshableState<T extends StatefulWidget> extends State<T> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget getFab(BuildContext context) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
||||||
@ -63,6 +67,7 @@ abstract class RefreshableState<T extends StatefulWidget> extends State<T> {
|
|||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: getAppBar(context),
|
appBar: getAppBar(context),
|
||||||
drawer: getDrawer(context),
|
drawer: getDrawer(context),
|
||||||
|
floatingActionButton: getFab(context),
|
||||||
body: RefreshIndicator(
|
body: RefreshIndicator(
|
||||||
onRefresh: refresh,
|
onRefresh: refresh,
|
||||||
child: getBody(context)
|
child: getBody(context)
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import 'package:InvenTree/inventree/stock.dart';
|
import 'package:InvenTree/inventree/stock.dart';
|
||||||
import 'package:InvenTree/inventree/part.dart';
|
import 'package:InvenTree/inventree/part.dart';
|
||||||
|
import 'package:InvenTree/widget/fields.dart';
|
||||||
import 'package:InvenTree/widget/location_display.dart';
|
import 'package:InvenTree/widget/location_display.dart';
|
||||||
import 'package:InvenTree/widget/part_detail.dart';
|
import 'package:InvenTree/widget/part_detail.dart';
|
||||||
import 'package:InvenTree/widget/refreshable_state.dart';
|
import 'package:InvenTree/widget/refreshable_state.dart';
|
||||||
@ -12,7 +13,7 @@ import 'package:InvenTree/api.dart';
|
|||||||
|
|
||||||
import 'package:InvenTree/widget/drawer.dart';
|
import 'package:InvenTree/widget/drawer.dart';
|
||||||
import 'package:InvenTree/widget/refreshable_state.dart';
|
import 'package:InvenTree/widget/refreshable_state.dart';
|
||||||
|
import 'package:flutter_typeahead/flutter_typeahead.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||||
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
|
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
|
||||||
@ -98,6 +99,9 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _addStockDialog() async {
|
void _addStockDialog() async {
|
||||||
|
|
||||||
|
_quantityController.clear();
|
||||||
|
|
||||||
showDialog(context: context,
|
showDialog(context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
@ -117,22 +121,10 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Text("Current Quantity: ${item.quantity}"),
|
Text("Current stock: ${item.quantity}"),
|
||||||
TextFormField(
|
QuantityField(
|
||||||
decoration: InputDecoration(
|
label: "Add Stock",
|
||||||
labelText: "Add stock",
|
|
||||||
),
|
|
||||||
keyboardType: TextInputType.numberWithOptions(signed: false, decimal: true),
|
|
||||||
controller: _quantityController,
|
controller: _quantityController,
|
||||||
validator: (value) {
|
|
||||||
if (value.isEmpty) return "Value cannot be empty";
|
|
||||||
|
|
||||||
double quantity = double.tryParse(value);
|
|
||||||
if (quantity == null) return "Value cannot be converted to a number";
|
|
||||||
if (quantity <= 0) return "Value must be positive";
|
|
||||||
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
TextFormField(
|
TextFormField(
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
@ -164,6 +156,9 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _removeStockDialog() {
|
void _removeStockDialog() {
|
||||||
|
|
||||||
|
_quantityController.clear();
|
||||||
|
|
||||||
showDialog(context: context,
|
showDialog(context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
@ -183,25 +178,11 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Text("Current quantity: ${item.quantity}"),
|
Text("Current stock: ${item.quantity}"),
|
||||||
TextFormField(
|
QuantityField(
|
||||||
decoration: InputDecoration(
|
label: "Remove stock",
|
||||||
labelText: "Remove stock",
|
|
||||||
),
|
|
||||||
controller: _quantityController,
|
controller: _quantityController,
|
||||||
keyboardType: TextInputType.numberWithOptions(signed: false, decimal: true),
|
max: item.quantity,
|
||||||
validator: (value) {
|
|
||||||
if (value.isEmpty) return "Value cannot be empty";
|
|
||||||
|
|
||||||
double quantity = double.tryParse(value);
|
|
||||||
|
|
||||||
if (quantity == null) return "Value cannot be converted to a number";
|
|
||||||
if (quantity <= 0) return "Value must be positive";
|
|
||||||
|
|
||||||
if (quantity > item.quantity) return "Cannot take more than current quantity";
|
|
||||||
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
TextFormField(
|
TextFormField(
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
@ -253,22 +234,10 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
TextFormField(
|
QuantityField(
|
||||||
decoration: InputDecoration(
|
label: "Count Stock",
|
||||||
labelText: "Count stock",
|
hint: "${item.quantity}",
|
||||||
hintText: "${item.quantity}",
|
|
||||||
),
|
|
||||||
controller: _quantityController,
|
controller: _quantityController,
|
||||||
keyboardType: TextInputType.numberWithOptions(signed: false, decimal: true),
|
|
||||||
validator: (value) {
|
|
||||||
if (value.isEmpty) return "Value cannot be empty";
|
|
||||||
|
|
||||||
double quantity = double.tryParse(value);
|
|
||||||
if (quantity == null) return "Value cannot be converted to a number";
|
|
||||||
if (quantity < 0) return "Value cannot be negative";
|
|
||||||
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
TextFormField(
|
TextFormField(
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
@ -354,13 +323,12 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Location information
|
// Location information
|
||||||
if (item.locationName.isNotEmpty) {
|
if (item.locationName.isNotEmpty) {
|
||||||
tiles.add(
|
tiles.add(
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text("Stock Location"),
|
title: Text("Stock Location"),
|
||||||
subtitle: Text("${item.locationName}"),
|
subtitle: Text("${item.locationPathString}"),
|
||||||
leading: FaIcon(FontAwesomeIcons.mapMarkerAlt),
|
leading: FaIcon(FontAwesomeIcons.mapMarkerAlt),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
if (item.locationId > 0) {
|
if (item.locationId > 0) {
|
||||||
@ -466,6 +434,24 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
return buttons;
|
return buttons;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget getBottomNavBar(BuildContext context) {
|
||||||
|
return BottomNavigationBar(
|
||||||
|
currentIndex: 0,
|
||||||
|
onTap: null,
|
||||||
|
items: const <BottomNavigationBarItem> [
|
||||||
|
BottomNavigationBarItem(
|
||||||
|
icon: FaIcon(FontAwesomeIcons.infoCircle),
|
||||||
|
title: Text("Details"),
|
||||||
|
),
|
||||||
|
BottomNavigationBarItem(
|
||||||
|
icon: FaIcon(FontAwesomeIcons.history),
|
||||||
|
title: Text("History"),
|
||||||
|
)
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget getBody(BuildContext context) {
|
Widget getBody(BuildContext context) {
|
||||||
return ListView(
|
return ListView(
|
||||||
@ -474,23 +460,12 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget getFab(BuildContext context) {
|
||||||
|
return SpeedDial(
|
||||||
this.context = context;
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
appBar: getAppBar(context),
|
|
||||||
drawer: getDrawer(context),
|
|
||||||
floatingActionButton: SpeedDial(
|
|
||||||
visible: true,
|
visible: true,
|
||||||
animatedIcon: AnimatedIcons.menu_close,
|
animatedIcon: AnimatedIcons.menu_close,
|
||||||
heroTag: 'stock-item-fab',
|
heroTag: 'stock-item-fab',
|
||||||
children: actionButtons(),
|
children: actionButtons(),
|
||||||
),
|
|
||||||
body: RefreshIndicator(
|
|
||||||
onRefresh: refresh,
|
|
||||||
child: getBody(context)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
14
pubspec.lock
14
pubspec.lock
@ -76,6 +76,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.7.0"
|
version: "0.7.0"
|
||||||
|
flutter_keyboard_visibility:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: flutter_keyboard_visibility
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.7.0"
|
||||||
flutter_launcher_icons:
|
flutter_launcher_icons:
|
||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description:
|
description:
|
||||||
@ -102,6 +109,13 @@ packages:
|
|||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
|
flutter_typeahead:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: flutter_typeahead
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "1.8.0"
|
||||||
flutter_web_plugins:
|
flutter_web_plugins:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description: flutter
|
description: flutter
|
||||||
|
@ -33,6 +33,7 @@ dependencies:
|
|||||||
font_awesome_flutter: ^8.8.1 # FontAwesome icon set
|
font_awesome_flutter: ^8.8.1 # FontAwesome icon set
|
||||||
flutter_speed_dial: ^1.2.5 # FAB menu elements
|
flutter_speed_dial: ^1.2.5 # FAB menu elements
|
||||||
sentry: ^3.0.1 # Error reporting
|
sentry: ^3.0.1 # Error reporting
|
||||||
|
flutter_typeahead: ^1.8.0 # Auto-complete input field
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user