简体   繁体   English

需要帮助显示带有颤振/飞镖的图像

[英]Need help displaying an image with flutter/dart

i am brand new here and have been looking around for a while but can't seem to find anything relating to what i'm trying to do.我在这里是全新的,已经四处寻找了一段时间,但似乎找不到与我正在尝试做的事情有关的任何事情。 I have created a simple quiz app and i have collected the users answers and associated them with a score.我创建了一个简单的测验应用程序,我收集了用户的答案并将它们与分数相关联。 I have worked out how to display text to the user based on their score but am now trying to work out how i would go about displaying an image that is based on their result.我已经研究了如何根据他们的分数向用户显示文本,但现在我正在尝试弄清楚我将如何 go 来显示基于他们的结果的图像。 I have made a separate widget for the image(s) but am having trouble implementing it into my "results" widget.我已经为图像制作了一个单独的小部件,但在将其实现到我的“结果”小部件中时遇到了麻烦。 Is this the best way to go for something like this?这是 go 的最佳方法吗? Using a Boolean then redirecting them to the specified widget, or would it be better to display the image using a different way in the results widget itself.使用 Boolean 然后将它们重定向到指定的小部件,或者在结果小部件本身中使用不同的方式显示图像会更好。 Any tips or advice as i'm extremely new to all of this, even links to text tutorials or videos would be really appreciated.任何提示或建议,因为我对这一切都非常陌生,甚至是文本教程或视频的链接,我都会非常感激。 Apologies if this is already out there somewhere i probably just didn't look hard enough.抱歉,如果这已经存在于某个地方,我可能只是看起来不够努力。 Cheers干杯

You can load a "RootWidget" which decides what image to show.您可以加载决定要显示什么图像的“RootWidget”。

Your Score View:您的分数视图:

Column(
  children: <Widget>[
    Text(
     'YourScore',
    ),
    ImageChooser(
      score
    ),
  ],
),

ImageChooser build Method: ImageChooser 构建方法:

Widget build(BuildContext context) {
    if(widget.score > 10) {
        return Image(YOUR_IMAGE_1);
    } else {
        return Image(YOUR_IMAGE_2);
    }      
}

EDIT: You need to pass the score in the constructor of the StatefulWidget编辑:您需要在 StatefulWidget 的构造函数中传递分数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM