0
votes

Am Trying to access a field by the name imgPath that is in class BusinessCard Here's the Code

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);
...}

Here's Where am trying to access it from

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)
          ),}`
2

2 Answers

0
votes

You can solve this issue by changing your code like this

dynamic card = BusinessCard;

to

dynamic card = BusinessCard();

In fact you are trying to get imagePath in BusinessCard which is a type not a value. You need to create an instance of this class before accessing instance variables (by calling default constructor with ExampleClass()or by calling static constructor like ExampleClass.fromTest(test)).

You can learn more Here

0
votes

It looks like you didn't give any parameter to your BusinessCard constructor when declaring the variable card. Also you named your getter _imgPath. In Flutter if you put an _ in front of something it means that it is private so you don't have access to it outside from its class.