![](/img/trans.png)
[英]How can I use checkboxlisttile in alertDialog in flutter?
[英]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.