Issue
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)
),}`
Solution
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
Answered By – Constantin N.
Answer Checked By – Candace Johnson (FlutterFixes Volunteer)