Couldn’t find headerLabel to use it. Tried to use variable headerLabel but could not find solution
class ProfileHeaderLabel extends StatelessWidget {
final String headerLabel;
const ProfileHeaderLabel({
Key? key, required this.headerLabel
}): super(key: key)
@override
Widget build(BuildContext context) {
return SizedBox(
height: 40,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
SizedBox(
height: 40,
width: 50,
child: Divider(
color: Colors.grey,
thickness: 1,
),
),
// 'Account info'
Text(
headerLabel,
style: TextStyle(
color: Colors.grey, fontSize: 24, fontWeight: FontWeight.w600),
),
Couldn’t find headerLabel to use it.
3
Answers
Thank you @MendelG like the way you put it above works, also putting const before
Sizedbox
not before [
Like this:
In your code:
you’re trying to use a non-constant expression (
headerLabel
) inside a constant (const [...]
).But in your case,
headerLabel
is not a constant because its value is determined at runtime, not at compile-time.To solve the issue, just remove
const
from the Row’s children:Related: (to learn more about
const
)You need to add semicolon at the end of your constructor
const ProfileHeaderLabel({
Key? key, required this.headerLabel
}): super(key: key);
You need to remove const keyword after Row children
You’re trying to access the non-const variable (headerLabel) that’s why it is throwing the error.