mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 13:36:50 +00:00
Refactor showFormDialog function
This commit is contained in:
parent
07017c4745
commit
d290f98445
@ -39,14 +39,6 @@ class _CompanyDetailState extends RefreshableState<CompanyDetailWidget> {
|
|||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
void _saveCompany(Map<String, String> values) async {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
|
|
||||||
await company.update(values: values);
|
|
||||||
|
|
||||||
refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
void editCompanyDialog() {
|
void editCompanyDialog() {
|
||||||
|
|
||||||
// Values which can be edited
|
// Values which can be edited
|
||||||
@ -54,55 +46,7 @@ class _CompanyDetailState extends RefreshableState<CompanyDetailWidget> {
|
|||||||
var _description;
|
var _description;
|
||||||
var _website;
|
var _website;
|
||||||
|
|
||||||
showFormDialog(L10().edit,
|
// TODO - API form
|
||||||
key: _editCompanyKey,
|
|
||||||
actions: <Widget>[
|
|
||||||
TextButton(
|
|
||||||
child: Text(L10().cancel),
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.pop(context);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
TextButton(
|
|
||||||
child: Text(L10().save),
|
|
||||||
onPressed: () {
|
|
||||||
if (_editCompanyKey.currentState!.validate()) {
|
|
||||||
_editCompanyKey.currentState!.save();
|
|
||||||
|
|
||||||
_saveCompany({
|
|
||||||
"name": _name,
|
|
||||||
"description": _description,
|
|
||||||
"website": _website,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
fields: <Widget>[
|
|
||||||
StringField(
|
|
||||||
label: L10().name,
|
|
||||||
initial: company.name,
|
|
||||||
onSaved: (value) {
|
|
||||||
_name = value;
|
|
||||||
},
|
|
||||||
),
|
|
||||||
StringField(
|
|
||||||
label: L10().description,
|
|
||||||
initial: company.description,
|
|
||||||
onSaved: (value) {
|
|
||||||
_description = value;
|
|
||||||
},
|
|
||||||
),
|
|
||||||
StringField(
|
|
||||||
label: L10().website,
|
|
||||||
initial: company.website,
|
|
||||||
allowEmpty: true,
|
|
||||||
onSaved: (value) {
|
|
||||||
_website = value;
|
|
||||||
},
|
|
||||||
)
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Widget> _companyTiles() {
|
List<Widget> _companyTiles() {
|
||||||
|
@ -184,24 +184,24 @@ Future<void> showTimeoutError() async {
|
|||||||
await showServerError(L10().timeout, L10().noResponse);
|
await showServerError(L10().timeout, L10().noResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
void showFormDialog(String title, {String? acceptText, String? cancelText, GlobalKey<FormState>? key, List<Widget>? fields, List<Widget>? actions, Function? callback}) {
|
void showFormDialog(String title, {String? acceptText, String? cancelText, GlobalKey<FormState>? key, List<Widget>? fields, Function? callback}) {
|
||||||
|
|
||||||
BuildContext? dialogContext;
|
|
||||||
|
|
||||||
String _accept = acceptText ?? L10().save;
|
String _accept = acceptText ?? L10().save;
|
||||||
String _cancel = cancelText ?? L10().cancel;
|
String _cancel = cancelText ?? L10().cancel;
|
||||||
|
|
||||||
// Undefined actions = OK + Cancel
|
List<Widget> _fields = fields ?? [];
|
||||||
if (actions == null) {
|
|
||||||
actions = <Widget>[
|
OneContext().showDialog(
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: Text(title),
|
||||||
|
actions: <Widget>[
|
||||||
TextButton(
|
TextButton(
|
||||||
child: Text(_cancel),
|
child: Text(_cancel),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
// Close the form
|
// Close the form
|
||||||
var _ctx = dialogContext;
|
Navigator.pop(context);
|
||||||
if (_ctx != null) {
|
|
||||||
Navigator.pop(_ctx);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
TextButton(
|
TextButton(
|
||||||
@ -214,12 +214,7 @@ void showFormDialog(String title, {String? acceptText, String? cancelText, Globa
|
|||||||
if (_key.currentState!.validate()) {
|
if (_key.currentState!.validate()) {
|
||||||
_key.currentState!.save();
|
_key.currentState!.save();
|
||||||
|
|
||||||
// Close the dialog
|
Navigator.pop(context);
|
||||||
var _ctx = dialogContext;
|
|
||||||
|
|
||||||
if (_ctx != null) {
|
|
||||||
Navigator.pop(_ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Callback
|
// Callback
|
||||||
if (callback != null) {
|
if (callback != null) {
|
||||||
@ -229,17 +224,7 @@ void showFormDialog(String title, {String? acceptText, String? cancelText, Globa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
];
|
],
|
||||||
}
|
|
||||||
|
|
||||||
List<Widget> _fields = fields ?? [];
|
|
||||||
|
|
||||||
OneContext().showDialog(
|
|
||||||
builder: (BuildContext context) {
|
|
||||||
dialogContext = context;
|
|
||||||
return AlertDialog(
|
|
||||||
title: Text(title),
|
|
||||||
actions: actions,
|
|
||||||
content: Form(
|
content: Form(
|
||||||
key: key,
|
key: key,
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user