简体   繁体   English

Flutter:为什么我不能在 AlertDialog 中使用图像?

[英]Flutter: Why can't I use an Image in an AlertDialog?

I just want to put an Image and an Text in this AlertDialog , but the Imagename images/jonglieren.jpg is red underlined.我只想在此AlertDialog中放置一个Image和一个Text ,但图像名称images/jonglieren.jpg红色下划线。 The shown "Error: The getter 'images' isn't defined for the class 'MyHomePage'" doesn't help too.显示的“错误:未为 class 'MyHomePage' 定义 getter 'images'”也无济于事。 Here's the function :这是function

void inform() {
      showDialog<AlertDialog>(
          context: context,
          builder: (BuildContext context) {
            return AlertDialog(
              actions: <Widget>[
                Column(
                  children: <Widget>[
                    Text('Jonglieren'), Image.asset(images/jonglieren.jpg)
                  ],
                )
              ],
            );
          });
    }

Your image path should be a string(it should be in a quotation)你的图像路径应该是一个字符串(它应该在引号中)

from images/jonglieren.jpg to 'images/jonglieren.jpg'从 images/jonglieren.jpg 到 'images/jonglieren.jpg'

void inform() {
      showDialog<AlertDialog>(
          context: context,
          builder: (BuildContext context) {
            return AlertDialog(
              actions: <Widget>[
                Column(
                  children: <Widget>[
                    Text('Jonglieren'), Image.asset('images/jonglieren.jpg')
                  ],
                )
              ],
            );
          });
    }

The Image.asset constructor takes a String name as its parameter. Image.asset构造函数将String name作为其参数。 So to solve this issue just give your asset path as a String.因此,要解决此问题,只需将您的资产路径作为字符串提供即可。

void inform() {
      showDialog<AlertDialog>(
          context: context,
          builder: (BuildContext context) {
            return AlertDialog(
              actions: <Widget>[
                Column(
                  children: <Widget>[
                    Text('Jonglieren'), Image.asset('images/jonglieren.jpg')
                  ],
                )
              ],
            );
          });
    }

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

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