Settings
This commit is contained in:
parent
1a7dd51d98
commit
c20f33c573
|
|
@ -1,59 +1,90 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:invoiceninja_flutter/constants.dart';
|
||||||
|
|
||||||
class CustomField extends StatelessWidget {
|
class CustomField extends StatelessWidget {
|
||||||
const CustomField({
|
const CustomField({
|
||||||
@required this.controller,
|
@required this.controller,
|
||||||
@required this.labelText,
|
@required this.label,
|
||||||
@required this.options,
|
|
||||||
this.initialValue,
|
this.initialValue,
|
||||||
});
|
});
|
||||||
|
|
||||||
final TextEditingController controller;
|
final TextEditingController controller;
|
||||||
final String labelText;
|
final String label;
|
||||||
final List<String> options;
|
|
||||||
final String initialValue;
|
final String initialValue;
|
||||||
|
|
||||||
|
String get _fieldType {
|
||||||
|
if (label.contains('|')) {
|
||||||
|
final value = label.split('|').last;
|
||||||
|
if ([kFieldTypeSingleLineText, kFieldTypeDate, kFieldTypeSwitch]
|
||||||
|
.contains(value)) {
|
||||||
|
return value;
|
||||||
|
} else {
|
||||||
|
return kFieldTypeDropdown;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return kFieldTypeMultiLineText;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String get _fieldLabel {
|
||||||
|
if (label.contains('|')) {
|
||||||
|
return label.split('|').first;
|
||||||
|
} else {
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> get _fieldOptions {
|
||||||
|
final data = label.split('|').last.split(',');
|
||||||
|
return data.where((data) => data.isNotEmpty).toList();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (labelText.isEmpty) {
|
if (label == null) {
|
||||||
return Container();
|
return SizedBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.isEmpty) {
|
print('## BUILD: $label: $_fieldType $_fieldLabel $_fieldOptions');
|
||||||
return TextFormField(
|
|
||||||
autocorrect: false,
|
|
||||||
controller: controller,
|
|
||||||
keyboardType: TextInputType.text,
|
|
||||||
maxLines: 2,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText: labelText,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
final menuItems = options
|
|
||||||
.map((option) => PopupMenuItem<String>(
|
|
||||||
value: option,
|
|
||||||
child: Text(option),
|
|
||||||
))
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
return PopupMenuButton<String>(
|
|
||||||
padding: EdgeInsets.zero,
|
switch (_fieldType) {
|
||||||
initialValue: initialValue,
|
case kFieldTypeSingleLineText:
|
||||||
itemBuilder: (BuildContext context) => menuItems,
|
case kFieldTypeMultiLineText:
|
||||||
onSelected: (value) => controller.text = value,
|
return TextFormField(
|
||||||
child: InkWell(
|
autocorrect: false,
|
||||||
child: IgnorePointer(
|
controller: controller,
|
||||||
child: TextFormField(
|
keyboardType: TextInputType.text,
|
||||||
controller: controller,
|
maxLines: _fieldType == kFieldTypeSingleLineText ? 1 : 3,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: labelText,
|
labelText: _fieldLabel,
|
||||||
suffixIcon: const Icon(Icons.arrow_drop_down),
|
),
|
||||||
|
);
|
||||||
|
case kFieldTypeDropdown:
|
||||||
|
return PopupMenuButton<String>(
|
||||||
|
padding: EdgeInsets.zero,
|
||||||
|
initialValue: initialValue,
|
||||||
|
itemBuilder: (BuildContext context) => _fieldOptions
|
||||||
|
.map((option) => PopupMenuItem<String>(
|
||||||
|
value: option,
|
||||||
|
child: Text(option),
|
||||||
|
))
|
||||||
|
.toList(),
|
||||||
|
onSelected: (value) => controller.text = value,
|
||||||
|
child: InkWell(
|
||||||
|
child: IgnorePointer(
|
||||||
|
child: TextFormField(
|
||||||
|
controller: controller,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
labelText: _fieldLabel,
|
||||||
|
suffixIcon: const Icon(Icons.arrow_drop_down),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
);
|
default:
|
||||||
|
return SizedBox();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -344,13 +344,11 @@ class ContactEditDetailsState extends State<ContactEditDetails> {
|
||||||
),
|
),
|
||||||
CustomField(
|
CustomField(
|
||||||
controller: _custom1Controller,
|
controller: _custom1Controller,
|
||||||
labelText: company.getCustomFieldLabel(CustomFieldType.contact1),
|
label: company.customFields[CustomFieldType.contact1],
|
||||||
options: company.getCustomFieldValues(CustomFieldType.contact1),
|
|
||||||
),
|
),
|
||||||
CustomField(
|
CustomField(
|
||||||
controller: _custom2Controller,
|
controller: _custom2Controller,
|
||||||
labelText: company.getCustomFieldLabel(CustomFieldType.contact2),
|
label: company.customFields[CustomFieldType.contact2],
|
||||||
options: company.getCustomFieldValues(CustomFieldType.contact2),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -144,13 +144,11 @@ class ClientEditDetailsState extends State<ClientEditDetails> {
|
||||||
),
|
),
|
||||||
CustomField(
|
CustomField(
|
||||||
controller: _custom1Controller,
|
controller: _custom1Controller,
|
||||||
labelText: company.getCustomFieldLabel(CustomFieldType.client1),
|
label: company.customFields[CustomFieldType.client1],
|
||||||
options: company.getCustomFieldValues(CustomFieldType.client1),
|
|
||||||
),
|
),
|
||||||
CustomField(
|
CustomField(
|
||||||
controller: _custom2Controller,
|
controller: _custom2Controller,
|
||||||
labelText: company.getCustomFieldLabel(CustomFieldType.client2),
|
label: company.customFields[CustomFieldType.client2],
|
||||||
options: company.getCustomFieldValues(CustomFieldType.client2),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -173,13 +173,11 @@ class ExpenseEditDetailsState extends State<ExpenseEditDetails> {
|
||||||
),
|
),
|
||||||
CustomField(
|
CustomField(
|
||||||
controller: _custom1Controller,
|
controller: _custom1Controller,
|
||||||
labelText: company.getCustomFieldLabel(CustomFieldType.expense1),
|
label: company.customFields[CustomFieldType.expense1],
|
||||||
options: company.getCustomFieldValues(CustomFieldType.expense1),
|
|
||||||
),
|
),
|
||||||
CustomField(
|
CustomField(
|
||||||
controller: _custom2Controller,
|
controller: _custom2Controller,
|
||||||
labelText: company.getCustomFieldLabel(CustomFieldType.expense2),
|
label: company.customFields[CustomFieldType.expense2],
|
||||||
options: company.getCustomFieldValues(CustomFieldType.expense2),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -130,17 +130,11 @@ class _GroupEditState extends State<GroupEdit> {
|
||||||
),
|
),
|
||||||
CustomField(
|
CustomField(
|
||||||
controller: _custom1Controller,
|
controller: _custom1Controller,
|
||||||
labelText:
|
label: company.customFields[CustomFieldType.group1],
|
||||||
company.getCustomFieldLabel(CustomFieldType.group1),
|
|
||||||
options: company
|
|
||||||
.getCustomFieldValues(CustomFieldType.group1),
|
|
||||||
),
|
),
|
||||||
CustomField(
|
CustomField(
|
||||||
controller: _custom2Controller,
|
controller: _custom2Controller,
|
||||||
labelText:
|
label: company.customFields[CustomFieldType.group2],
|
||||||
company.getCustomFieldLabel(CustomFieldType.group2),
|
|
||||||
options: company
|
|
||||||
.getCustomFieldValues(CustomFieldType.group2),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -256,13 +256,11 @@ class InvoiceEditDetailsState extends State<InvoiceEditDetails> {
|
||||||
),
|
),
|
||||||
CustomField(
|
CustomField(
|
||||||
controller: _custom1Controller,
|
controller: _custom1Controller,
|
||||||
labelText: company.getCustomFieldLabel(CustomFieldType.invoice1),
|
label: company.customFields[CustomFieldType.invoice1],
|
||||||
options: company.getCustomFieldValues(CustomFieldType.invoice1),
|
|
||||||
),
|
),
|
||||||
CustomField(
|
CustomField(
|
||||||
controller: _custom2Controller,
|
controller: _custom2Controller,
|
||||||
labelText: company.getCustomFieldLabel(CustomFieldType.invoice2),
|
label: company.customFields[CustomFieldType.invoice2],
|
||||||
options: company.getCustomFieldValues(CustomFieldType.invoice2),
|
|
||||||
),
|
),
|
||||||
company.getCustomFieldLabel(CustomFieldType.surcharge1).isNotEmpty
|
company.getCustomFieldLabel(CustomFieldType.surcharge1).isNotEmpty
|
||||||
? DecoratedFormField(
|
? DecoratedFormField(
|
||||||
|
|
|
||||||
|
|
@ -240,13 +240,11 @@ class ItemEditDetailsState extends State<ItemEditDetails> {
|
||||||
),
|
),
|
||||||
CustomField(
|
CustomField(
|
||||||
controller: _custom1Controller,
|
controller: _custom1Controller,
|
||||||
labelText: company.getCustomFieldLabel(CustomFieldType.product1),
|
label: company.customFields[CustomFieldType.product1],
|
||||||
options: company.getCustomFieldValues(CustomFieldType.product1),
|
|
||||||
),
|
),
|
||||||
CustomField(
|
CustomField(
|
||||||
controller: _custom2Controller,
|
controller: _custom2Controller,
|
||||||
labelText: company.getCustomFieldLabel(CustomFieldType.product2),
|
label: company.customFields[CustomFieldType.product2],
|
||||||
options: company.getCustomFieldValues(CustomFieldType.product2),
|
|
||||||
),
|
),
|
||||||
DecoratedFormField(
|
DecoratedFormField(
|
||||||
label: localization.unitCost,
|
label: localization.unitCost,
|
||||||
|
|
|
||||||
|
|
@ -178,17 +178,11 @@ class _ProductEditState extends State<ProductEdit> {
|
||||||
),
|
),
|
||||||
CustomField(
|
CustomField(
|
||||||
controller: _custom1Controller,
|
controller: _custom1Controller,
|
||||||
labelText:
|
label: company.customFields[CustomFieldType.product1],
|
||||||
company.getCustomFieldLabel(CustomFieldType.product1),
|
|
||||||
options:
|
|
||||||
company.getCustomFieldValues(CustomFieldType.product1),
|
|
||||||
),
|
),
|
||||||
CustomField(
|
CustomField(
|
||||||
controller: _custom2Controller,
|
controller: _custom2Controller,
|
||||||
labelText:
|
label: company.customFields[CustomFieldType.product2],
|
||||||
company.getCustomFieldLabel(CustomFieldType.product2),
|
|
||||||
options:
|
|
||||||
company.getCustomFieldValues(CustomFieldType.product2),
|
|
||||||
),
|
),
|
||||||
DecoratedFormField(
|
DecoratedFormField(
|
||||||
label: localization.price,
|
label: localization.price,
|
||||||
|
|
|
||||||
|
|
@ -223,17 +223,11 @@ class _ProjectEditState extends State<ProjectEdit> {
|
||||||
),
|
),
|
||||||
CustomField(
|
CustomField(
|
||||||
controller: _custom1Controller,
|
controller: _custom1Controller,
|
||||||
labelText:
|
label: company.customFields[CustomFieldType.project1],
|
||||||
company.getCustomFieldLabel(CustomFieldType.project1),
|
|
||||||
options: company
|
|
||||||
.getCustomFieldValues(CustomFieldType.project1),
|
|
||||||
),
|
),
|
||||||
CustomField(
|
CustomField(
|
||||||
controller: _custom2Controller,
|
controller: _custom2Controller,
|
||||||
labelText:
|
label: company.customFields[CustomFieldType.project2],
|
||||||
company.getCustomFieldLabel(CustomFieldType.project2),
|
|
||||||
options: company
|
|
||||||
.getCustomFieldValues(CustomFieldType.project2),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -254,31 +254,19 @@ class _CompanyDetailsState extends State<CompanyDetails>
|
||||||
),
|
),
|
||||||
CustomField(
|
CustomField(
|
||||||
controller: _custom1Controller,
|
controller: _custom1Controller,
|
||||||
labelText:
|
label: company.customFields[CustomFieldType.company1],
|
||||||
company.getCustomFieldLabel(CustomFieldType.company1),
|
|
||||||
options:
|
|
||||||
company.getCustomFieldValues(CustomFieldType.company1),
|
|
||||||
),
|
),
|
||||||
CustomField(
|
CustomField(
|
||||||
controller: _custom2Controller,
|
controller: _custom2Controller,
|
||||||
labelText:
|
label: company.customFields[CustomFieldType.company2],
|
||||||
company.getCustomFieldLabel(CustomFieldType.company2),
|
|
||||||
options:
|
|
||||||
company.getCustomFieldValues(CustomFieldType.company2),
|
|
||||||
),
|
),
|
||||||
CustomField(
|
CustomField(
|
||||||
controller: _custom3Controller,
|
controller: _custom3Controller,
|
||||||
labelText:
|
label: company.customFields[CustomFieldType.company3],
|
||||||
company.getCustomFieldLabel(CustomFieldType.company3),
|
|
||||||
options:
|
|
||||||
company.getCustomFieldValues(CustomFieldType.company3),
|
|
||||||
),
|
),
|
||||||
CustomField(
|
CustomField(
|
||||||
controller: _custom4Controller,
|
controller: _custom4Controller,
|
||||||
labelText:
|
label: company.customFields[CustomFieldType.company4],
|
||||||
company.getCustomFieldLabel(CustomFieldType.company4),
|
|
||||||
options:
|
|
||||||
company.getCustomFieldValues(CustomFieldType.company4),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -152,13 +152,11 @@ class _TaskEditDetailsState extends State<TaskEditDetails> {
|
||||||
),
|
),
|
||||||
CustomField(
|
CustomField(
|
||||||
controller: _custom1Controller,
|
controller: _custom1Controller,
|
||||||
labelText: company.getCustomFieldLabel(CustomFieldType.task1),
|
label: company.customFields[CustomFieldType.task1],
|
||||||
options: company.getCustomFieldValues(CustomFieldType.task1),
|
|
||||||
),
|
),
|
||||||
CustomField(
|
CustomField(
|
||||||
controller: _custom2Controller,
|
controller: _custom2Controller,
|
||||||
labelText: company.getCustomFieldLabel(CustomFieldType.task2),
|
label: company.customFields[CustomFieldType.task2],
|
||||||
options: company.getCustomFieldValues(CustomFieldType.task2),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -330,13 +330,11 @@ class ContactEditDetailsState extends State<ContactEditDetails> {
|
||||||
),
|
),
|
||||||
CustomField(
|
CustomField(
|
||||||
controller: _custom1Controller,
|
controller: _custom1Controller,
|
||||||
labelText: company.getCustomFieldLabel(CustomFieldType.contact1),
|
label: company.customFields[CustomFieldType.contact1],
|
||||||
options: company.getCustomFieldValues(CustomFieldType.contact1),
|
|
||||||
),
|
),
|
||||||
CustomField(
|
CustomField(
|
||||||
controller: _custom2Controller,
|
controller: _custom2Controller,
|
||||||
labelText: company.getCustomFieldLabel(CustomFieldType.contact2),
|
label: company.customFields[CustomFieldType.contact2],
|
||||||
options: company.getCustomFieldValues(CustomFieldType.contact2),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -127,13 +127,11 @@ class VendorEditDetailsState extends State<VendorEditDetails> {
|
||||||
),
|
),
|
||||||
CustomField(
|
CustomField(
|
||||||
controller: _custom1Controller,
|
controller: _custom1Controller,
|
||||||
labelText: company.getCustomFieldLabel(CustomFieldType.vendor1),
|
label: company.customFields[CustomFieldType.vendor1],
|
||||||
options: company.getCustomFieldValues(CustomFieldType.vendor1),
|
|
||||||
),
|
),
|
||||||
CustomField(
|
CustomField(
|
||||||
controller: _custom2Controller,
|
controller: _custom2Controller,
|
||||||
labelText: company.getCustomFieldLabel(CustomFieldType.vendor2),
|
label: company.customFields[CustomFieldType.vendor2],
|
||||||
options: company.getCustomFieldValues(CustomFieldType.vendor2),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue