gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 04:06:10 25 4
gpt4 key购买 nike

我是 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com