Skip to content
This repository was archived by the owner on Mar 3, 2025. It is now read-only.

Commit 911272d

Browse files
committed
[Fix] Group, Svg, Alignment
1 parent ea92cd5 commit 911272d

File tree

5 files changed

+48
-15
lines changed

5 files changed

+48
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Adobe XD Flutter Code Generate - Plugin
2-
<a href="https://github.com/thize/xd-to-flutter/releases"><img src="https://img.shields.io/badge/Xd%20to%20Flutter-v3.1.0-blue"/></a>
2+
<a href="https://github.com/thize/xd-to-flutter/releases"><img src="https://img.shields.io/badge/Xd%20to%20Flutter-v3.1.1-blue"/></a>
33

44
⚠️ **If you encounter an issue or have any feedback which you think could improve Plugin, please open an issue [here](https://github.com/thize/xd-to-flutter/issues)**
55

src/util.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
const scenegraph = require("scenegraph");
2-
const { Path, Line, Group, Polygon, BooleanGroup, Artboard, ImageFill, RepeatGrid, SymbolInstance, Text } = require("scenegraph");
2+
const { Path, Line, Group, Polygon, BooleanGroup, Artboard, RepeatGrid, SymbolInstance, Text } = require("scenegraph");
33
const { ArtboardWidget } = require("./widgets/artboard");
44
const { ComponentWidget } = require("./widgets/component");
55
const { ContainerWidget } = require("./widgets/container");
66
const { GroupWidget } = require("./widgets/group");
77
const { GridWidget } = require("./widgets/grid");
8-
const { InkWellWidget } = require("./widgets/inkwell");
98
const { SvgWidget } = require("./widgets/svg");
109
const { TextWidget } = require("./widgets/text");
1110
const { MaskWidget } = require("./widgets/mask");
@@ -158,6 +157,36 @@ function applyRegex(str) {
158157
str = _applySCRegexWithTag(str, getNumberRegex, null, 'Offset');
159158
str = _applySCRegexWithTag(str, getNumberRegex, null, 'elliptical');
160159
str = _applySCRegexWithTag(str, getNumberRegex, null, 'circular');
160+
const element = document.getElementById('numbersMethodName');
161+
let methodName = element != null ? element.value : element;
162+
methodName = methodName ? methodName : '';
163+
if (methodName != "") {
164+
let indexOf = str.indexOf("TextStyle");
165+
while (indexOf != -1) {
166+
let ini = indexOf + 10;
167+
let index = ini;
168+
let qtdParentheses = 1;
169+
let end;
170+
while (end == null) {
171+
if (str[index] == '(') {
172+
qtdParentheses++
173+
} else if (str[index] == ')') {
174+
qtdParentheses--;
175+
}
176+
if (qtdParentheses == 0) {
177+
end = index;
178+
}
179+
index++;
180+
}
181+
let fix = str.substring(ini, end);
182+
console.log('fix height');
183+
fix = fix.replace(new RegExp(`height: ${methodName}\(.*\)`, 'gm'), (value) => {
184+
return value.replace(`${methodName}(`, '').replace(')', '');
185+
});
186+
str = str.substring(0, ini) + fix + str.substring(end)
187+
indexOf = str.indexOf("TextStyle", end);
188+
}
189+
}
161190
return str;
162191
}
163192

src/widgets/group.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ class GroupWidget {
1111
const { removeItemsFromGroup } = require("../util");
1212
const ungroupedItems = removeItemsFromGroup(this.xdNode.children);
1313
const itemsDart = itemsToDart(ungroupedItems);
14+
return `\n// Group: ${this.xdNode.name}\n${itemsDart}`;
15+
/*
1416
return `
1517
Container(
1618
// Group: ${this.xdNode.name}
17-
alignment: Alignment.center,
1819
width: ${this.xdNode.localBounds.width},
1920
height: ${this.xdNode.localBounds.height},
2021
child: ${itemsDart},
2122
)`;
23+
*/
2224
}
2325
}
2426

src/widgets/svg.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,7 @@ class SvgWidget {
1717
const node = this.xdNode;
1818
const path = new Path(node);
1919
path.shapes = this.shapes;
20-
let height = node.height;
21-
height = height != null ? height : node.localBounds.height;
22-
height = height == 0 ? 1 : height;
23-
let width = node.width;
24-
width = width != null ? width : node.localBounds.width;
25-
width = width == 0 ? 1 : width;
26-
return `SizedBox(
27-
width: ${width},
28-
height: ${height},
29-
child: ${path.toString()},
30-
)`;
20+
return path.toString();
3121
}
3222

3323

@@ -71,9 +61,18 @@ class Path {
7161
toString() {
7262
let svg;
7363
svg = `'${this.toSvgString()}'`;
64+
const node = this.xdNode;
65+
let height = node.height;
66+
height = height != null ? height : node.localBounds.height;
67+
height = height == 0 ? 1 : height;
68+
let width = node.width;
69+
width = width != null ? width : node.localBounds.width;
70+
width = width == 0 ? 1 : width;
7471
return `SvgPicture.string(
7572
// ${this.xdNode.name}
7673
${svg},
74+
width: ${width},
75+
height: ${height},
7776
)`;
7877
}
7978

src/widgets/util/xd_alignment_to_dart_alignment.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ function xdAlignmentToDartAlignment(x, y) {
55
const dx = fix(fixAlignment(x));
66
const dy = fix(fixAlignment(y));
77
const align = `Alignment(${dx},${dy})`;
8+
const dif = Math.abs(dx - dy);
9+
if(dif < 0.02) return 'Alignment.center';
10+
console.log(`dif = ${dif}`);
811
return nameAlignment[align] ? nameAlignment[align] : align;
912
}
1013

0 commit comments

Comments
 (0)