簡體   English   中英

Flutter:為什么我不能在 AlertDialog 中使用圖像?

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

我只想在此AlertDialog中放置一個Image和一個Text ,但圖像名稱images/jonglieren.jpg紅色下划線。 顯示的“錯誤:未為 class 'MyHomePage' 定義 getter 'images'”也無濟於事。 這是function

void inform() {
      showDialog<AlertDialog>(
          context: context,
          builder: (BuildContext context) {
            return AlertDialog(
              actions: <Widget>[
                Column(
                  children: <Widget>[
                    Text('Jonglieren'), Image.asset(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')
                  ],
                )
              ],
            );
          });
    }

Image.asset構造函數將String name作為其參數。 因此,要解決此問題,只需將您的資產路徑作為字符串提供即可。

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