2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-05-07 01:38:55 +00:00

More refactoring

Helper function to display a scrollable form in a dialog
This commit is contained in:
Oliver Walters 2020-04-18 22:25:59 +10:00
parent e8a4a387ea
commit af104717ab
2 changed files with 162 additions and 108 deletions

View File

@ -39,3 +39,26 @@ 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
)
)
)
);
}
);
}

View File

@ -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,10 +103,8 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
_quantityController.clear(); _quantityController.clear();
showDialog(context: context, showFormDialog(context, "Add Stock",
builder: (BuildContext context) { key: _addStockKey,
return AlertDialog(
title: Text("Add Stock"),
actions: <Widget>[ actions: <Widget>[
FlatButton( FlatButton(
child: Text("Add"), child: Text("Add"),
@ -114,13 +113,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
}, },
) )
], ],
content: Form( fields: <Widget> [
key: _addStockKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text("Current stock: ${item.quantity}"), Text("Current stock: ${item.quantity}"),
QuantityField( QuantityField(
label: "Add Stock", label: "Add Stock",
@ -133,13 +126,8 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
controller: _notesController, controller: _notesController,
) )
], ],
)
),
); );
} }
);
// TODO - Form for adding stock
}
void _removeStock() async { void _removeStock() async {
Navigator.of(context).pop(); Navigator.of(context).pop();
@ -159,10 +147,8 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
_quantityController.clear(); _quantityController.clear();
showDialog(context: context, showFormDialog(context, "Remove Stock",
builder: (BuildContext context) { key: _removeStockKey,
return AlertDialog(
title: Text("Remove Stock"),
actions: <Widget>[ actions: <Widget>[
FlatButton( FlatButton(
child: Text("Remove"), child: Text("Remove"),
@ -171,13 +157,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
}, },
) )
], ],
content: Form( fields: <Widget>[
key: _removeStockKey,
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text("Current stock: ${item.quantity}"), Text("Current stock: ${item.quantity}"),
QuantityField( QuantityField(
label: "Remove stock", label: "Remove stock",
@ -191,10 +171,6 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
controller: _notesController, controller: _notesController,
), ),
], ],
)
),
);
}
); );
} }
@ -214,12 +190,10 @@ 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"),
actions: <Widget>[
FlatButton( FlatButton(
child: Text("Count"), child: Text("Count"),
onPressed: () { onPressed: () {
@ -227,13 +201,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
}, },
) )
], ],
content: Form( fields: <Widget> [
key: _countStockKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
QuantityField( QuantityField(
label: "Count Stock", label: "Count Stock",
hint: "${item.quantity}", hint: "${item.quantity}",
@ -245,11 +213,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
), ),
controller: _notesController, 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}"),
);
}
),
],
);
} }
/* /*