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