Skip to content

Commit fa20e8d

Browse files
committed
add trailing comma to widget props & update tests
1 parent f633b62 commit fa20e8d

22 files changed

Lines changed: 362 additions & 355 deletions

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.10",
6+
"version": "0.0.13",
77
"icon": "images/logo.png",
88
"repository": {
99
"type": "github",

src/generators/class-generator.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,24 +132,29 @@ export class ClassCodeGenerator {
132132
...controllers.filter(a => !a.isPrivate).map(a => a.name),
133133
...vars.filter(a => a.type === 'FormGroup').map(a => a.name)
134134
];
135-
136-
return `
137-
138-
class ${rootWidget.controller}Base {
139-
bool _loaded = false;
140-
Map<String, dynamic> _attachedControllers = Map();
141-
${varsLines.join('\n ')}
135+
136+
let formCode = '';
137+
if (formControls.length) {
138+
formCode = `
139+
Map<String, dynamic> _attachedControllers = Map();
142140
143141
dynamic _attachController(String controlName, controllerBuilder) {
144142
if (_attachedControllers.containsKey(controlName)) {
145-
final controller = _attachedControllers[controlName];
143+
final controller = _attachedControllers[controlName];
146144
return controller;
147145
}
148-
final controller = controllerBuilder();
146+
final controller = controllerBuilder();
149147
_attachedControllers[controlName] = controller;
150148
formGroup.get(controlName).attachTextEditingController(controller);
151-
return controller;
152-
}
149+
return controller;
150+
}`;
151+
}
152+
153+
return `
154+
155+
class ${rootWidget.controller}Base {
156+
bool _loaded = false;
157+
${varsLines.join('\n ')}${formCode}
153158
154159
void _load(BuildContext context) {
155160
if (!_loaded) {

src/generators/widget-generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class WidgetCodeGenerator {
4141

4242
const propsCode = props.filter(a => a.trim()).join(',\n');
4343
if (!widget.isPropertyElement && widget.type) {
44-
code += `${widget.type}(\n${propsCode}\n${tabs})`;
44+
code += `${widget.type}(\n${propsCode}${propsCode.trim() ? ',' : ''}\n${tabs})`;
4545
}
4646
else {
4747
code += propsCode;

src/property-handlers/builder.test.ts

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ suite("Builder Tests", function () {
1818
itemBuilder: (BuildContext context) {
1919
return PopupMenuItem(
2020
child: Text(
21-
'text'
22-
)
21+
'text',
22+
),
2323
);
24-
}
24+
},
2525
)
2626
`;
2727

@@ -46,10 +46,10 @@ suite("Builder Tests", function () {
4646
itemBuilder: (context, index) {
4747
return PopupMenuItem(
4848
child: Text(
49-
'text'
50-
)
49+
'text',
50+
),
5151
);
52-
}
52+
},
5353
)
5454
`;
5555

@@ -75,10 +75,10 @@ suite("Builder Tests", function () {
7575
itemBuilder: (context, index) {
7676
return PopupMenuItem(
7777
child: Text(
78-
'text'
79-
)
78+
'text',
79+
),
8080
);
81-
}
81+
},
8282
),
8383
() => Container(width: 0, height: 0)
8484
)
@@ -110,11 +110,11 @@ suite("Builder Tests", function () {
110110
return RaisedButton(
111111
onPressed: event,
112112
child: Text(
113-
'Login'
114-
)
113+
'Login',
114+
),
115115
);
116-
}
117-
)
116+
},
117+
),
118118
)
119119
`;
120120

@@ -150,12 +150,12 @@ suite("Builder Tests", function () {
150150
return RaisedButton(
151151
onPressed: event,
152152
child: Text(
153-
'Login'
154-
)
153+
'Login',
154+
),
155155
);
156-
}
156+
},
157157
);
158-
}
158+
},
159159
)
160160
`;
161161

@@ -181,10 +181,10 @@ suite("Builder Tests", function () {
181181
final item = items == null || items.length <= myIndex || items.length == 0 ? null : items[myIndex];
182182
return PopupMenuItem(
183183
child: Text(
184-
'text'
185-
)
184+
'text',
185+
),
186186
);
187-
}
187+
},
188188
)
189189
`;
190190

@@ -218,12 +218,12 @@ suite("Builder Tests", function () {
218218
final item = itemsStreamValue == null || itemsStreamValue.length <= index || itemsStreamValue.length == 0 ? null : itemsStreamValue[index];
219219
return PopupMenuItem(
220220
child: Text(
221-
'text'
222-
)
221+
'text',
222+
),
223223
);
224-
}
224+
},
225225
);
226-
}
226+
},
227227
)
228228
`;
229229

@@ -250,15 +250,15 @@ suite("Builder Tests", function () {
250250
itemBuilder: (context, index) {
251251
final item = component.items == null || component.items.length <= index || component.items.length == 0 ? null : component.items[index];
252252
return Text(
253-
item.title
253+
item.title,
254254
);
255255
},
256256
separatorBuilder: (context, index) {
257257
final item = component.items == null || component.items.length <= index || component.items.length == 0 ? null : component.items[index];
258258
return Divider(
259259
260260
);
261-
}
261+
},
262262
)
263263
`;
264264

@@ -293,17 +293,17 @@ suite("Builder Tests", function () {
293293
itemBuilder: (context, index) {
294294
final item = componentItemsValue == null || componentItemsValue.length <= index || componentItemsValue.length == 0 ? null : componentItemsValue[index];
295295
return Text(
296-
item.title
296+
item.title,
297297
);
298298
},
299299
separatorBuilder: (context, index) {
300300
final item = component.items == null || component.items.length <= index || component.items.length == 0 ? null : component.items[index];
301301
return Divider(
302302
303303
);
304-
}
304+
},
305305
);
306-
}
306+
},
307307
)
308308
`;
309309

@@ -338,17 +338,17 @@ suite("Builder Tests", function () {
338338
itemBuilder: (context, index) {
339339
final item = component.items == null || component.items.length <= index || component.items.length == 0 ? null : component.items[index];
340340
return Text(
341-
item.title
341+
item.title,
342342
);
343343
},
344344
separatorBuilder: (context, index) {
345345
final item = componentItemsValue == null || componentItemsValue.length <= index || componentItemsValue.length == 0 ? null : componentItemsValue[index];
346346
return Divider(
347347
348348
);
349-
}
349+
},
350350
);
351-
}
351+
},
352352
)
353353
`;
354354

@@ -383,17 +383,17 @@ suite("Builder Tests", function () {
383383
itemBuilder: (context, index) {
384384
final item = componentItemsValue == null || componentItemsValue.length <= index || componentItemsValue.length == 0 ? null : componentItemsValue[index];
385385
return Text(
386-
item.title
386+
item.title,
387387
);
388388
},
389389
separatorBuilder: (context, index) {
390390
final item = componentItemsValue == null || componentItemsValue.length <= index || componentItemsValue.length == 0 ? null : componentItemsValue[index];
391391
return Divider(
392392
393393
);
394-
}
394+
},
395395
);
396-
}
396+
},
397397
)
398398
`;
399399

@@ -420,19 +420,19 @@ suite("Builder Tests", function () {
420420
return Padding(
421421
padding: const EdgeInsets.all(11),
422422
child: Text(
423-
item.title
424-
)
423+
item.title,
424+
),
425425
);
426426
}
427427
if (item != null) {
428428
return Padding(
429429
padding: const EdgeInsets.all(11),
430430
child: Text(
431-
item.title
432-
)
431+
item.title,
432+
),
433433
);
434434
}
435-
}
435+
},
436436
)
437437
`;
438438

@@ -458,10 +458,10 @@ suite("Builder Tests", function () {
458458
return Padding(
459459
padding: const EdgeInsets.all(11),
460460
child: Text(
461-
item.title2
462-
)
461+
item.title2,
462+
),
463463
);
464-
}
464+
},
465465
)
466466
`;
467467

@@ -488,17 +488,17 @@ suite("Builder Tests", function () {
488488
Padding(
489489
padding: const EdgeInsets.all(11),
490490
child: Text(
491-
item.title2
492-
)
491+
item.title2,
492+
),
493493
),
494494
Padding(
495495
padding: const EdgeInsets.all(11),
496496
child: Text(
497-
item.title1
498-
)
497+
item.title1,
498+
),
499499
)
500500
];
501-
}
501+
},
502502
)
503503
`;
504504

@@ -521,9 +521,9 @@ suite("Builder Tests", function () {
521521
itemBuilder: (BuildContext context, index) {
522522
final item = component.items == null || component.items.length <= index || component.items.length == 0 ? null : component.items[index];
523523
return Text(
524-
item.title
524+
item.title,
525525
);
526-
}
526+
},
527527
)
528528
`;
529529

@@ -545,9 +545,9 @@ suite("Builder Tests", function () {
545545
ListView.builder(
546546
itemBuilder: (BuildContext context) {
547547
return Text(
548-
item.title
548+
item.title,
549549
);
550-
}
550+
},
551551
)
552552
`;
553553

src/property-handlers/builder.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,13 @@ export class BuilderHandler extends CustomPropertyHandler {
7878

7979
private resolveBuilder(element: parseXml.Element, attr: AttributeModel, builderData: any, wrapperWidget: WidgetModel | null, contentWidget: WidgetModel): { tempData: any, wrapperWidget: WidgetModel | null } | null {
8080
let childWidget = builderData.value;
81-
let arrayOfIfWidgets = null;
8281
if (!childWidget) {
8382
return null;
8483
}
8584

85+
let arrayOfIfWidgets = null;
86+
let hasArrayProp = false;
87+
8688
if (childWidget instanceof Array) {
8789
// get (if) widgets
8890
arrayOfIfWidgets = childWidget.filter(a => a.type === ':if');
@@ -91,14 +93,14 @@ export class BuilderHandler extends CustomPropertyHandler {
9193
childWidget = null;
9294
}
9395
else {
94-
const hasArrayProp = builderData.extraData.properties.filter((a: any) => a.name === 'array').length > 0;
96+
hasArrayProp = builderData.extraData.properties.filter((a: any) => a.name === 'array').length > 0;
9597
if (!hasArrayProp) {
9698
childWidget = childWidget[0];
9799
}
98100
}
99101
contentWidget.wrappedWidgets.push(...arrayOfIfWidgets);
100102
}
101-
else if (childWidget) {
103+
if (!hasArrayProp && childWidget) {
102104
contentWidget.wrappedWidgets.push(childWidget);
103105
}
104106

src/property-handlers/child-builder.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ suite("Child Builder Tests", function () {
1313
ListView(
1414
children: WidgetHelpers.mapToWidgetList(component.items, (item, index) {
1515
return Text(
16-
item.title
16+
item.title,
1717
);
18-
})
18+
}),
1919
)
2020
`;
2121

@@ -42,11 +42,11 @@ suite("Child Builder Tests", function () {
4242
return ListView(
4343
children: WidgetHelpers.mapToWidgetList(componentItemsValue, (item, index) {
4444
return Text(
45-
item.title
45+
item.title,
4646
);
47-
})
47+
}),
4848
);
49-
}
49+
},
5050
)
5151
`;
5252

0 commit comments

Comments
 (0)