mirror of
https://github.com/inventree/inventree-app.git
synced 2025-05-03 15:58:54 +00:00
More refactoring
Helper function to display a scrollable form in a dialog
This commit is contained in:
parent
e8a4a387ea
commit
af104717ab
@ -38,4 +38,27 @@ void showProgressDialog(BuildContext context, String title, String description)
|
|||||||
|
|
||||||
void hideProgressDialog(BuildContext context) {
|
void hideProgressDialog(BuildContext context) {
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
void showFormDialog(BuildContext context, String title, {GlobalKey<FormState> key, List<Widget> fields, List<Widget> actions}) {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: Text(title),
|
||||||
|
actions: actions,
|
||||||
|
content: Form(
|
||||||
|
key: key,
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: fields
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
@ -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/dialogs.dart';
|
||||||
import 'package:InvenTree/widget/fields.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';
|
||||||
@ -102,43 +103,30 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
|
|
||||||
_quantityController.clear();
|
_quantityController.clear();
|
||||||
|
|
||||||
showDialog(context: context,
|
showFormDialog(context, "Add Stock",
|
||||||
builder: (BuildContext context) {
|
key: _addStockKey,
|
||||||
return AlertDialog(
|
actions: <Widget>[
|
||||||
title: Text("Add Stock"),
|
FlatButton(
|
||||||
actions: <Widget>[
|
child: Text("Add"),
|
||||||
FlatButton(
|
onPressed: () {
|
||||||
child: Text("Add"),
|
if (_addStockKey.currentState.validate()) _addStock();
|
||||||
onPressed: () {
|
},
|
||||||
if (_addStockKey.currentState.validate()) _addStock();
|
)
|
||||||
},
|
],
|
||||||
)
|
fields: <Widget> [
|
||||||
],
|
Text("Current stock: ${item.quantity}"),
|
||||||
content: Form(
|
QuantityField(
|
||||||
key: _addStockKey,
|
label: "Add Stock",
|
||||||
child: Column(
|
controller: _quantityController,
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
),
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
TextFormField(
|
||||||
mainAxisSize: MainAxisSize.min,
|
decoration: InputDecoration(
|
||||||
children: <Widget>[
|
labelText: "Notes",
|
||||||
Text("Current stock: ${item.quantity}"),
|
|
||||||
QuantityField(
|
|
||||||
label: "Add Stock",
|
|
||||||
controller: _quantityController,
|
|
||||||
),
|
|
||||||
TextFormField(
|
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText: "Notes",
|
|
||||||
),
|
|
||||||
controller: _notesController,
|
|
||||||
)
|
|
||||||
],
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
);
|
controller: _notesController,
|
||||||
}
|
)
|
||||||
|
],
|
||||||
);
|
);
|
||||||
// TODO - Form for adding stock
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _removeStock() async {
|
void _removeStock() async {
|
||||||
@ -159,42 +147,30 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
|
|
||||||
_quantityController.clear();
|
_quantityController.clear();
|
||||||
|
|
||||||
showDialog(context: context,
|
showFormDialog(context, "Remove Stock",
|
||||||
builder: (BuildContext context) {
|
key: _removeStockKey,
|
||||||
return AlertDialog(
|
actions: <Widget>[
|
||||||
title: Text("Remove Stock"),
|
FlatButton(
|
||||||
actions: <Widget>[
|
child: Text("Remove"),
|
||||||
FlatButton(
|
onPressed: () {
|
||||||
child: Text("Remove"),
|
if (_removeStockKey.currentState.validate()) _removeStock();
|
||||||
onPressed: () {
|
},
|
||||||
if (_removeStockKey.currentState.validate()) _removeStock();
|
)
|
||||||
},
|
],
|
||||||
)
|
fields: <Widget>[
|
||||||
],
|
Text("Current stock: ${item.quantity}"),
|
||||||
content: Form(
|
QuantityField(
|
||||||
key: _removeStockKey,
|
label: "Remove stock",
|
||||||
child: Column(
|
controller: _quantityController,
|
||||||
mainAxisSize: MainAxisSize.min,
|
max: item.quantity,
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: <Widget>[
|
|
||||||
Text("Current stock: ${item.quantity}"),
|
|
||||||
QuantityField(
|
|
||||||
label: "Remove stock",
|
|
||||||
controller: _quantityController,
|
|
||||||
max: item.quantity,
|
|
||||||
),
|
|
||||||
TextFormField(
|
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText: "Notes",
|
|
||||||
),
|
|
||||||
controller: _notesController,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
);
|
TextFormField(
|
||||||
}
|
decoration: InputDecoration(
|
||||||
|
labelText: "Notes",
|
||||||
|
),
|
||||||
|
controller: _notesController,
|
||||||
|
),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,42 +190,30 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _countStockDialog() async {
|
void _countStockDialog() async {
|
||||||
showDialog(
|
|
||||||
context: context,
|
showFormDialog(context, "Count Stock",
|
||||||
builder: (BuildContext context) {
|
key: _countStockKey,
|
||||||
return AlertDialog(
|
actions: <Widget> [
|
||||||
title: Text("Count Stock"),
|
FlatButton(
|
||||||
actions: <Widget>[
|
child: Text("Count"),
|
||||||
FlatButton(
|
onPressed: () {
|
||||||
child: Text("Count"),
|
if (_countStockKey.currentState.validate()) _countStock();
|
||||||
onPressed: () {
|
},
|
||||||
if (_countStockKey.currentState.validate()) _countStock();
|
)
|
||||||
},
|
],
|
||||||
)
|
fields: <Widget> [
|
||||||
],
|
QuantityField(
|
||||||
content: Form(
|
label: "Count Stock",
|
||||||
key: _countStockKey,
|
hint: "${item.quantity}",
|
||||||
child: Column(
|
controller: _quantityController,
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
),
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
TextFormField(
|
||||||
mainAxisSize: MainAxisSize.min,
|
decoration: InputDecoration(
|
||||||
children: <Widget>[
|
labelText: "Notes",
|
||||||
QuantityField(
|
),
|
||||||
label: "Count Stock",
|
controller: _notesController,
|
||||||
hint: "${item.quantity}",
|
)
|
||||||
controller: _quantityController,
|
]
|
||||||
),
|
|
||||||
TextFormField(
|
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText: "Notes",
|
|
||||||
),
|
|
||||||
controller: _notesController,
|
|
||||||
)
|
|
||||||
],
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,8 +222,75 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
void _transferStockDialog() {
|
void _transferStockDialog() async {
|
||||||
// TODO - Form for transferring stock
|
|
||||||
|
var locations = await InvenTreeStockLocation().list(context);
|
||||||
|
final _selectedController = TextEditingController();
|
||||||
|
|
||||||
|
InvenTreeStockLocation selectedLocation;
|
||||||
|
|
||||||
|
_quantityController.text = "${item.quantity}";
|
||||||
|
|
||||||
|
showFormDialog(context, "Transfer Stock",
|
||||||
|
key: _moveStockKey,
|
||||||
|
actions: <Widget>[
|
||||||
|
FlatButton(
|
||||||
|
child: Text("Transfer"),
|
||||||
|
onPressed: () {
|
||||||
|
if (_moveStockKey.currentState.validate()) {
|
||||||
|
// TODO - Transfer!
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
|
fields: <Widget>[
|
||||||
|
QuantityField(
|
||||||
|
label: "Quantity",
|
||||||
|
controller: _quantityController,
|
||||||
|
max: item.quantity,
|
||||||
|
),
|
||||||
|
TypeAheadFormField(
|
||||||
|
textFieldConfiguration: TextFieldConfiguration(
|
||||||
|
controller: _selectedController,
|
||||||
|
autofocus: true,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: "Search for location",
|
||||||
|
border: OutlineInputBorder()
|
||||||
|
)
|
||||||
|
),
|
||||||
|
suggestionsCallback: (pattern) async {
|
||||||
|
var suggestions = List<InvenTreeStockLocation>();
|
||||||
|
|
||||||
|
for (var loc in locations) {
|
||||||
|
if (loc.matchAgainstString(pattern)) {
|
||||||
|
suggestions.add(loc as InvenTreeStockLocation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return suggestions;
|
||||||
|
},
|
||||||
|
validator: (value) {
|
||||||
|
if (selectedLocation == null) {
|
||||||
|
return "Select a location";
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
onSuggestionSelected: (suggestion) {
|
||||||
|
selectedLocation = suggestion as InvenTreeStockLocation;
|
||||||
|
_selectedController.text = selectedLocation.pathstring;
|
||||||
|
},
|
||||||
|
itemBuilder: (context, suggestion) {
|
||||||
|
var location = suggestion as InvenTreeStockLocation;
|
||||||
|
|
||||||
|
return ListTile(
|
||||||
|
title: Text("${location.pathstring}"),
|
||||||
|
subtitle: Text("${location.description}"),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user