I have a problem with passing image constructor. I passed one image there where I wanted and it automatically added something to the rest, when I didnt want it.
I try to pass it from here
class LvPopup extends StatelessWidget {
final String title;
final String users_info;
final String? image;
LvPopup({
super.key,
required this.title,
required this.users_info,
this.image,
});
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Column(
children: [
SizedBox(height: 10),
Column(
children: [
Row(
children: [
Text(
title,
style: TextStyle(color: PaidworkColors.lightTxtColor),
),
],
),
SizedBox(
height: 5,
),
Row(
children: [
Image.asset(image ?? ""),
Padding(
padding: const EdgeInsets.all(5.0),
child: Text(
users_info,
),
),
],
)
],
)
],
),
);
}
}
to there
LvPopup(
title: 'E-mail',
users_info: 'gmail.com',
),
SizedBox(
height: 5,
),
LvPopup(
users_info: 'Johny Bravo',
title: 'Name and Surname',
),
SizedBox(
height: 5,
),
LvPopup(
image: 'assets/images/blue_dot.png',
users_info: "In the process ",
title: 'Status',
),
SizedBox(
height: 5,
),
LvPopup(
users_info: '+0.00',
title: 'Earnings(USD)',
),
and the problem is that I want image only in:
LvPopup(
image: 'assets/images/blue_dot.png',
users_info: "In the process ",
title: 'Status',
),
but it throws an error to the rest and it says unable to load asset, when I dont want to pass image to the rest LvPopup only to that "Status"
here is an image:
2
Answers
You have an error in the line
Image.assets(image ?? "")
if the variable image is null, then you are trying to show an image along the path with an empty string and you will get an error,
it’s better to try this
if image is null display SizedBox()