Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 5924296

Browse files
committed
Use dart idioms
The tutorial should use dart idioms
1 parent e23019b commit 5924296

File tree

1 file changed

+25
-30
lines changed

1 file changed

+25
-30
lines changed

Chapter_04/lib/tooltip/tooltip_directive.dart

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,58 +21,54 @@ class Tooltip {
2121

2222
dom.Element tooltipElem;
2323

24-
Tooltip(dom.Element this.element, dom.Node this.node,
25-
Scope this.scope) {
26-
27-
element.onMouseEnter.listen((event) {
28-
_createTemplate();
29-
});
30-
31-
element.onMouseLeave.listen((event) {
32-
_destroyTemplate();
33-
});
24+
Tooltip(this.element, this.node, this.scope) {
25+
element
26+
..onMouseEnter.listen((_) => _createTemplate())
27+
..onMouseLeave.listen((_) => _destroyTemplate());
3428
}
3529

3630
_createTemplate() {
3731
assert(displayModel != null);
3832

3933
tooltipElem = new dom.DivElement();
4034

41-
dom.ImageElement imgElem = new dom.ImageElement();
42-
imgElem.width = displayModel.imgWidth;
43-
imgElem.src = displayModel.imgUrl;
35+
dom.ImageElement imgElem = new dom.ImageElement()
36+
..width = displayModel.imgWidth
37+
..src = displayModel.imgUrl;
4438
tooltipElem.append(imgElem);
4539

4640
if (displayModel.text != null) {
47-
dom.DivElement textSpan = new dom.DivElement();
48-
textSpan.appendText(displayModel.text);
49-
textSpan.style.color = "white";
50-
textSpan.style.fontSize = "smaller";
51-
textSpan.style.paddingBottom = "5px";
41+
dom.DivElement textSpan = new dom.DivElement()
42+
..appendText(displayModel.text)
43+
..style.color = "white"
44+
..style.fontSize = "smaller"
45+
..style.paddingBottom = "5px";
5246

5347
tooltipElem.append(textSpan);
5448
}
5549

56-
tooltipElem.style.padding = "5px";
57-
tooltipElem.style.paddingBottom = "0px";
58-
tooltipElem.style.backgroundColor = "black";
59-
tooltipElem.style.borderRadius = "5px";
60-
tooltipElem.style.width = "${displayModel.imgWidth.toString()}px";
50+
tooltipElem.style
51+
..padding = "5px"
52+
..paddingBottom = "0px"
53+
..backgroundColor = "black"
54+
..borderRadius = "5px"
55+
..width = "${displayModel.imgWidth.toString()}px";
6156

6257
// find the coordinates of the parent DOM element
6358
Rectangle bounds = element.getBoundingClientRect();
6459
int left = (bounds.left + dom.window.pageXOffset).toInt();
6560
int top = (bounds.top + dom.window.pageYOffset).toInt();
66-
int width = (bounds.width).toInt();
67-
int height = (bounds.height).toInt();
61+
int width = bounds.width.toInt();
62+
int height = bounds.height.toInt();
6863

6964
// position the tooltip.
7065
// Figure out where the containing element sits in the window.
7166
int tooltipLeft = left + width + 10;
7267
int tooltipTop = top - height;
73-
tooltipElem.style.position = "absolute";
74-
tooltipElem.style.top = "${tooltipTop}px";
75-
tooltipElem.style.left = "${tooltipLeft}px";
68+
tooltipElem.style
69+
..position = "absolute"
70+
..top = "${top - height}px"
71+
..left = "${left + width + 10}px";
7672

7773
// Add the tooltip to the document body. We add it here because
7874
// we need to position it absolutely, without reference to its
@@ -90,6 +86,5 @@ class TooltipModel {
9086
String text;
9187
int imgWidth;
9288

93-
TooltipModel(String this.imgUrl, String this.text,
94-
int this.imgWidth);
89+
TooltipModel(this.imgUrl, this.text, this.imgWidth);
9590
}

0 commit comments

Comments
 (0)