飞镖 /颤音:如何访问窗口小部件的成员变量 /值

发布于 2025-02-06 15:31:17 字数 581 浏览 1 评论 0原文

我有一个小部件列表。小部件是网站的背景图像。此列表中的最后一个小部件(图像)在屏幕上显示。当导航函数推送/pop时,最后一个元素将被删除/添加。

小部件中的一个字段(背景图)是一个名为“ Isforeground”的布尔。我需要访问它。

为什么?一些背景图像是前景,应在该网站的半透明背景纹理上方渲染,其中一些要在其后面呈现。

如果我有一个列表(背景图),而背景图则包含: 路径,BoxFit,不透明度,Isforeground(bool)等。如何在背景图列表中访问最后的背景图并访问其ISForground字段?

// psudo小部件树:

if(backdropimagelist.last的“ isforground”字段是错误的)背景图。 BackicktTextureWidget, if(Backdropimagelist.last's Isforground字段是真实的)背景图。last//在纹理上方渲染 headingwidget, 除了可能的话

(或替代方法),我会感谢您的帮助。替代性是每次按下/弹出按钮时,以编程为单位,并跟踪显示哪些图像的位置。首先知道哪些图像是前台/背景,并且从对象本身控制哪些图像是更整洁的IMO。 谢谢伙计们。

I have an list of widgets. The widgets are background images for a website. The last widget(image) in this list is displayed onscreen. As nav functions push/pop, the last element is removed/added.

One of the fields in the Widget(BackdropImage) is a bool called 'isForeground'. I need access to it.

Why? Some background images are foreground and are to be rendered above the site's semi-transparent background texture, some are to be rendered behind it.

If I have a List(BackDropImage) and the BackDropImage contains:
Path, BoxFit, Opacity, isForeground(bool) etc etc. How can I get access to the last BackDropImage in BackDropImage list and access its isForground field?

//PSUDO WIDGET TREE:

if(backdropImageList.last's 'isForground' field is FALSE) BackDropImage.last,//render here below the texture
BackgroundTextureWidget,
if(backdropImageList.last's isForground field is TRUE) BackDropImage.last //render here above the texture
HeadingWidget,
OtherWidgets

I'd appreciate help if possible (or alternative approaches). The alterative is to flip a bool programmatically every time a button is pressed/popped and keeping track of what images are displayed where. Knowing which images are fore/background in the first place and controlling from the object itself is much neater IMO.
Thanks folks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

网名女生简单气质 2025-02-13 15:31:18
 list.firstWhere((x) => x['isForground'] == true);
 list.firstWhere((x) => x['isForground'] == true);
烟雨扶苏 2025-02-13 15:31:18

小部件是一个抽象类。当使用具有成员变量的容器等小部件时,您需要以编程方式访问会员,可以这样做:

Widget testContainer = Container (width:100)
print(testContainer.width) // WON'T WORK
print((testContainer as Container).width) // WILL WORK 

要访问小部件列表中的单个小部件的成员变量:

List<Widget> listOfWidgets = [Container(color:Colors.blue), Container(color:Colors.red), Container(color:Colors.green)]

void printColorsOfAllContainers () {

for (var element in listOfWidgets) {
    if (element is Container) {
      print(element.color);
    }
  }
}

另外,您也可以执行类似的事情:

void printColorsOfAllContainers() {
  final List<Color> listOfContainerColours = [];
  for (var element in listOfWidgets) {
    element as Container;
    listOfContainerColours.add(element.color!);
  }
}

Widget is an abstract class. When working with Widgets like Container etc that have member variables you need to access programmatically, it can be done like this:

Widget testContainer = Container (width:100)
print(testContainer.width) // WON'T WORK
print((testContainer as Container).width) // WILL WORK 

To access the member variables of individual Widgets in a list of Widgets:

List<Widget> listOfWidgets = [Container(color:Colors.blue), Container(color:Colors.red), Container(color:Colors.green)]

void printColorsOfAllContainers () {

for (var element in listOfWidgets) {
    if (element is Container) {
      print(element.color);
    }
  }
}

Alternatively, you can also do things like this:

void printColorsOfAllContainers() {
  final List<Color> listOfContainerColours = [];
  for (var element in listOfWidgets) {
    element as Container;
    listOfContainerColours.add(element.color!);
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文