GeneratedFormSubForm UI improvements

This commit is contained in:
Imran Remtulla
2024-01-11 19:43:17 -05:00
parent 76a6a509cd
commit e18e7298bc

View File

@@ -510,9 +510,10 @@ class _GeneratedFormState extends State<GeneratedForm> {
]); ]);
} else if (widget.items[r][e] is GeneratedFormSubForm) { } else if (widget.items[r][e] is GeneratedFormSubForm) {
List<Widget> subformColumn = []; List<Widget> subformColumn = [];
var formItems = (widget.items[r][e] as GeneratedFormSubForm).items;
var compact = formItems.length == 1 && formItems[0].length == 1;
for (int i = 0; i < values[fieldKey].length; i++) { for (int i = 0; i < values[fieldKey].length; i++) {
var items = (widget.items[r][e] as GeneratedFormSubForm) var items = formItems
.items
.map((x) => x.map((y) { .map((x) => x.map((y) {
y.defaultValue = values[fieldKey]?[i]?[y.key]; y.defaultValue = values[fieldKey]?[i]?[y.key];
return y; return y;
@@ -525,14 +526,15 @@ class _GeneratedFormState extends State<GeneratedForm> {
subformColumn.add(Column( subformColumn.add(Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
const Divider(), if (!compact)
const SizedBox( const SizedBox(
height: 16, height: 16,
), ),
Text( if (!compact)
'${(widget.items[r][e] as GeneratedFormSubForm).label} (${i + 1})', Text(
style: const TextStyle(fontWeight: FontWeight.bold), '${(widget.items[r][e] as GeneratedFormSubForm).label} (${i + 1})',
), style: const TextStyle(fontWeight: FontWeight.bold),
),
GeneratedForm( GeneratedForm(
key: internalFormKey, key: internalFormKey,
items: items, items: items,
@@ -567,13 +569,12 @@ class _GeneratedFormState extends State<GeneratedForm> {
Icons.delete_outline_rounded, Icons.delete_outline_rounded,
)) ))
], ],
), )
], ],
)); ));
} }
subformColumn.add(Padding( subformColumn.add(Padding(
padding: EdgeInsets.only( padding: const EdgeInsets.only(bottom: 0, top: 8),
bottom: values[fieldKey].length > 0 ? 24 : 0, top: 8),
child: Row( child: Row(
children: [ children: [
Expanded( Expanded(
@@ -591,9 +592,6 @@ class _GeneratedFormState extends State<GeneratedForm> {
], ],
), ),
)); ));
if (values[fieldKey].length > 0) {
subformColumn.add(const Divider());
}
formInputs[r][e] = Column(children: subformColumn); formInputs[r][e] = Column(children: subformColumn);
} }
} }