Skip to content

Commit e86c00d

Browse files
committed
fixes bug in multi-child <if> element
1 parent 9d5c7c4 commit e86c00d

6 files changed

Lines changed: 25 additions & 14 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "XML Layout for Flutter",
44
"description": "XML Layout for Flutter. Brings Angular's style to Flutter!",
55
"publisher": "WaseemDev",
6-
"version": "0.0.13",
6+
"version": "0.0.16",
77
"icon": "images/logo.png",
88
"repository": {
99
"type": "github",

src/property-handlers/child-wrapper-property.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class ChildWrapperPropertyHandler extends WrapperPropertyHandler {
2121
attr.value = property.value !== null && property.value !== undefined ? property.value : attr.value;
2222
let value = property.targetProperty ? ValueTransformersProvider.transform(attr.value, property.targetProperty, this.targetWidgetType) : attr.value;
2323

24-
const propertyName = this.propertyResolver.isUnNamedParamaeter(property.targetProperty, this.targetWidgetType) ? '' : property.targetProperty;
24+
const propertyName = this.propertyResolver.isUnNamedParameter(property.targetProperty, this.targetWidgetType) ? '' : property.targetProperty;
2525

2626
const newChildWidget: WidgetModel = {
2727
controllers: [],

src/property-handlers/if-element.test.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -570,14 +570,15 @@ Container(
570570
<Row>
571571
<if value="ifCondition">
572572
<Text text="1" />
573+
<Text text="2" />
573574
</if>
574575
<elseIf value="elseIfCondition">
575-
<Text text="2" />
576576
<Text text="3" />
577+
<Text text="4" />
577578
</elseIf>
578579
<else>
579-
<Text text="4" />
580580
<Text text="5" />
581+
<Text text="6" />
581582
</else>
582583
</Row>
583584
`;
@@ -591,27 +592,30 @@ Container(
591592
() => [
592593
Text(
593594
1,
595+
),
596+
Text(
597+
2,
594598
)
595599
]
596600
),
597601
SwitchCaseMultiChild(
598602
elseIfCondition,
599603
() => [
600604
Text(
601-
2,
605+
3,
602606
),
603607
Text(
604-
3,
608+
4,
605609
)
606610
]
607611
),
608612
],
609613
() => [
610614
Text(
611-
4,
615+
5,
612616
),
613617
Text(
614-
5,
618+
6,
615619
)
616620
]
617621
),

src/property-handlers/if-element.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,20 @@ export class IfElementHandler extends CustomPropertyHandler {
2727
resolvePropertyElement(ifElement: parseXml.Element, widgetResolveResult: WidgetResolveResult, parent: parseXml.Element, parentChildren: parseXml.Element[], resolveWidget: (element: parseXml.Element, parent: parseXml.Element) => WidgetResolveResult): WidgetModel {
2828
const ifChains: IfModel[] = [];
2929
const wrappers: WidgetModel[] = [];
30-
30+
const multipleChild = widgetResolveResult.widget instanceof Array;
31+
3132
// apply binding for <if> element
3233
const ifBoundResult = this.propertyResolver.pipeValueResolver.resolve(ifElement, 'value', widgetResolveResult.propertyElementProperties.filter(a => a.name === 'value')[0].value, widgetResolveResult.widget);
34+
if (ifBoundResult.wrapperWidget && multipleChild) {
35+
throw new Error("::You can't use behavior or stream pipe on <if> element that has more than one child. Instead wrap the children with Column or Row.");
36+
}
37+
3338
const ifConditionValue = ifBoundResult.value;
39+
const childWidget: any[] = multipleChild ? (widgetResolveResult.widget as any) : [widgetResolveResult.widget];
3440
wrappers.push(ifBoundResult.wrapperWidget as any);
3541
ifChains.push({
3642
condition: ifConditionValue,
37-
childWidget: [widgetResolveResult.widget]
43+
childWidget: [...childWidget]
3844
});
3945

4046

@@ -168,13 +174,13 @@ export class IfElementHandler extends CustomPropertyHandler {
168174
code += ifChains.map(a => {
169175
return `SwitchCase${hasMultipleChild ? 'MultiChild' : ''}(
170176
${tabs} ${a.condition},
171-
${tabs} () => ${hasMultipleChild ? `[\n${itemTabs} ` : ''}${a.childWidget.map(c => generateChildWidgetCode(c, tabsLevel + 3 + (hasMultipleChild ? 1 : 0))).join(`,\n${itemTabs} `)}${hasMultipleChild ? `\n${itemTabs}]` : ''}
177+
${tabs} () => ${hasMultipleChild ? `[\n${itemTabs} ` : ''}${a.childWidget.map(c => generateChildWidgetCode(c, tabsLevel + 3 + (hasMultipleChild ? 1 : 0))).join(`,\n${itemTabs} `) || 'null'}${hasMultipleChild ? `\n${itemTabs}]` : ''}
172178
${tabs} ),`;
173179
}).join(`\n${tabs} `);
174180

175181
code += `
176182
${tabs} ],
177-
${tabs} () => ${hasMultipleChild ? `[\n${elseItemsTabs} ` : ''}${elseCode}${hasMultipleChild ? `\n${elseItemsTabs}]` : ''}
183+
${tabs} () => ${hasMultipleChild ? `[\n${elseItemsTabs} ` : ''}${elseCode || 'null'}${hasMultipleChild ? `\n${elseItemsTabs}]` : ''}
178184
${tabs})`;
179185

180186
return code;

src/property-handlers/wrapper-property.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export class WrapperPropertyHandler extends CustomPropertyHandler {
125125
}
126126

127127
protected createWrapperWidget(widget: WidgetModel, targetProperty: string, value: string, onWrapped: ((wrapper: WidgetModel) => void)[]): { wrapperWidget: WidgetModel, propertyToUpdateAfterBinding: PropertyModel | null } {
128-
const propertyName = this.propertyResolver.isUnNamedParamaeter(targetProperty, this.targetWidgetType) ? '' : targetProperty;
128+
const propertyName = this.propertyResolver.isUnNamedParameter(targetProperty, this.targetWidgetType) ? '' : targetProperty;
129129

130130
const wrapperWidget: WidgetModel = {
131131
controllers: [],

src/resolvers/widget-resolver.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,8 @@ export class WidgetResolver {
308308

309309
if (!result) {
310310
const arrayProperties: any = {
311-
'DropdownButton': ['items']
311+
'DropdownButton': ['items'],
312+
'CustomScrollView': ['slivers']
312313
};
313314
result = arrayProperties[parentName] && arrayProperties[parentName].filter((a: any) => a === name).length === 1 ||
314315
!!this.config.arrayProperties && this.config.arrayProperties[parentName] && this.config.arrayProperties[parentName].filter(a => a === name).length === 1;

0 commit comments

Comments
 (0)