Am试图通过类BusinessCard中的名称imgPath访问字段这是代码
class BusinessCard extends StatelessWidget {
final String imgPath;
final String bsnName;
final String bsnDescription;
final String bsnLocation;
final String bsnReview;
get _imgPath => imgPath;
BusinessCard(
this.imgPath, this.bsnName, this.bsnDescription, this.bsnLocation, this.bsnReview);
...}
在这里尝试从中访问它
class _DetailsTopPartState extends State<DetailsTopPart> {
Color fcl = const Color(0xffff005d);
Color lcl = const Color(0xffeb0ec6);
Color txt = const Color(0xff042fc9);
dynamic card = BusinessCard;
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(card._imgPath)
),}`
似乎在声明变量BusinessCard
时没有给card
构造函数任何参数。您也将自己的吸气剂命名为_imgPath
。在Flutter中,如果您将_
放在某物前面,则表示它是私有的,因此您无法从其类的外部访问它。