NoSuchMethodError:类'_Type'没有实例获取方法'imgPath'

问题描述 投票:0回答:1

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)
          ),}`
android flutter dart flutter-layout flutter-animation
1个回答
0
投票

似乎在声明变量BusinessCard时没有给card构造函数任何参数。您也将自己的吸气剂命名为_imgPath。在Flutter中,如果您将_放在某物前面,则表示它是私有的,因此您无法从其类的外部访问它。

© www.soinside.com 2019 - 2024. All rights reserved.