dart - 如何使用dart_web_toolkit设置元素位置?

标签 dart dart-web-toolkit

我是 Dart 的新手,需要创建动态dom结构。
目前,我使用dart_web_toolkit,但我缺少元素的位置函数。
您可以设置元素的宽度和高度,但不能设置位置(上,左)。

我在那儿想什么吗,或者有人可以给我解决方案?

编辑:
我有一个带有2个按钮的标签,我可以使用“setPixelSize”编辑按钮的大小
但是我需要类似“b1.setPosition”的东西,而且我找不到此方法来定位我的元素(在此示例按钮中)。
目前,它们只是相对于Label而言而已。

final el = querySelector('#body');

ui.Label rootLabel = new ui.Label();
rootLabel.addStyleName("root-style");
ui.RootPanel.get().addWidget(rootLabel, el);

final el1 = querySelector('.root-style');

ui.Button b1 = new ui.Button();
b1.text = "Button 1";
b1.addStyleName("b1");
b1.setPixelSize(30, 50);
ui.RootPanel.get().addWidget(b1, el1);

ui.Button b2 = new ui.Button();
b2.text = "Button 2";
b2.addStyleName("b2");
b1.setPixelSize(60,60);
ui.RootPanel.get().addWidget(b2, el1);

最佳答案

我只是觉得有点https://github.com/akserg/dart_web_toolkit/blob/afac7aac09e3bcd9d3e1f926815eb85040e46e07/lib/src/ui/button_base.dart的代码
似乎您应该通过调用Element获得b1.getElement()实例,该实例应允许访问所有元素属性,例如

b1.getElement().style
  ..position = 'absolute'
  ..top = '10px'
  ..left = '25px';

虽然没有测试。

关于dart - 如何使用dart_web_toolkit设置元素位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27101139/

相关文章:

flutter - 在启动Flutter之前我是否需要了解Dart

dart - 在Dart中是什么意思?

dart - 使用 material-dropdown-select 时 DomPopupSourceFactory 提供程序错误

dart - flutter 如何创建文件夹以将文件存储在内部存储中

dart - 如何在 Dart 中使用 int 与在 c# 或 java 中使用 int 相同