0

我希望我的所有类对象都有一个独特的图像。这是我的 CardClass:

class CardClass {
  int deger;
  String tip;
  int id;
  String image;

  CardClass(this.deger, this.tip, this.id, this.image);

  @override
  String toString() {
    return '{ ${deger}, ${tip}}';
  }
}

如何为我的所有对象定义图像?谢谢你。

lass CardBrain {
  List<CardClass> cardbank = [
    CardClass(1, "maca", 1, "images/dice1.png")]

我的 Pubspec.yaml:

flutter:
  assets:
    - images/dice1.png

它说:

无法加载资产:images/dice1.png

在此处输入图像描述

4

1 回答 1

0

我在我的类中有一个包含图像路径的字符串属性也是如此。

类 myClass(){String imagePath;[...]}

myClass myClassVariable = myClass(imagePath: 'Path');

我在需要时使用 Image.assets Widget 加载图像。

Image.asset(myClassVariable.imagePath, width:50, height:50, ),

于 2020-12-30T13:54:37.177 回答