diff --git a/lib/api_form.dart b/lib/api_form.dart index 514d3752..3e4bc60b 100644 --- a/lib/api_form.dart +++ b/lib/api_form.dart @@ -60,6 +60,8 @@ class APIFormField { String get helpText => (data['help_text'] ?? '').toString(); + String get placeholderText => (data['placeholder'] ?? '').toString(); + // Construct a widget for this input Widget constructField() { switch (type) { @@ -81,7 +83,17 @@ class APIFormField { return TextFormField( decoration: InputDecoration( labelText: required ? label + "*" : label, - hintText: helpText, + labelStyle: TextStyle( + fontWeight: FontWeight.bold, + fontSize: 22, + color: hasErrors() ? Color.fromRGBO(250, 50, 50, 1) : Color.fromRGBO(50, 50, 50, 1), + ), + helperText: helpText, + helperStyle: TextStyle( + fontStyle: FontStyle.italic, + color: hasErrors() ? Color.fromRGBO(205, 50, 50, 1) : Color.fromRGBO(50, 50, 50, 1), + ), + hintText: placeholderText, ), initialValue: value ?? '', onSaved: (val) { @@ -89,7 +101,7 @@ class APIFormField { }, validator: (value) { if (required && (value == null || value.isEmpty)) { - return L10().valueCannotBeEmpty; + // return L10().valueCannotBeEmpty; } }, ); @@ -199,7 +211,12 @@ Future launchApiForm(BuildContext context, String title, String url, Map APIFormWidget(title, url, formFields)) + MaterialPageRoute(builder: (context) => APIFormWidget( + title, + url, + formFields, + onSuccess: onSuccess, + )) ); } @@ -214,10 +231,20 @@ class APIFormWidget extends StatefulWidget { final List fields; - APIFormWidget(this.title, this.url, this.fields, {Key? key}) : super(key: key); + Function? onSuccess; + + APIFormWidget( + this.title, + this.url, + this.fields, + { + Key? key, + this.onSuccess, + } + ) : super(key: key); @override - _APIFormWidgetState createState() => _APIFormWidgetState(title, url, fields); + _APIFormWidgetState createState() => _APIFormWidgetState(title, url, fields, onSuccess); } @@ -232,7 +259,9 @@ class _APIFormWidgetState extends State { List fields; - _APIFormWidgetState(this.title, this.url, this.fields) : super(); + Function? onSuccess; + + _APIFormWidgetState(this.title, this.url, this.fields, this.onSuccess) : super(); List _buildForm() { @@ -252,7 +281,11 @@ class _APIFormWidgetState extends State { ListTile( title: Text( error, - style: TextStyle(color: Color.fromRGBO(250, 50, 50, 1)), + style: TextStyle( + color: Color.fromRGBO(250, 50, 50, 1), + fontStyle: FontStyle.italic, + fontSize: 16, + ), ) ) ); @@ -307,7 +340,12 @@ class _APIFormWidgetState extends State { // TODO: Display a snackBar - // TODO: Run custom onSuccess function + // Run custom onSuccess function + var successFunc = onSuccess; + + if (successFunc != null) { + successFunc(); + } return; case 400: // Form submission / validation error diff --git a/lib/widget/part_detail.dart b/lib/widget/part_detail.dart index 46187b80..d717b2a1 100644 --- a/lib/widget/part_detail.dart +++ b/lib/widget/part_detail.dart @@ -174,13 +174,6 @@ class _PartDisplayState extends RefreshableState { void _editPartDialog(BuildContext context) { - // Values which can be edited - var _name; - var _description; - var _ipn; - var _keywords; - var _link; - launchApiForm( context, L10().editPart, @@ -196,52 +189,6 @@ class _PartDisplayState extends RefreshableState { modelData: part.jsondata, onSuccess: refresh, ); - - return; - - showFormDialog(L10().editPart, - key: _editPartKey, - callback: () { - _savePart({ - "name": _name, - "description": _description, - "IPN": _ipn, - "keywords": _keywords, - "link": _link - }); - }, - fields: [ - StringField( - label: L10().name, - initial: part.name, - onSaved: (value) => _name = value, - ), - StringField( - label: L10().description, - initial: part.description, - onSaved: (value) => _description = value, - ), - StringField( - label: L10().internalPartNumber, - initial: part.IPN, - allowEmpty: true, - onSaved: (value) => _ipn = value, - ), - StringField( - label: L10().keywords, - initial: part.keywords, - allowEmpty: true, - onSaved: (value) => _keywords = value, - ), - StringField( - label: L10().link, - initial: part.link, - allowEmpty: true, - onSaved: (value) => _link = value - ) - ] - ); - } Widget headerTile() {