abhi
abhi

Reputation: 25

The constructor being called is not a const

I was just getting started with flutter and I am trying to create a small profile page I saw on YouTube. I built the page by stacking widgets under the children property of a Column widget. I have put the keyword 'const' before the children list. When I tried to add a Row Widget as one of the children I started to get this error:

The constructor being called isn't a const constructor.
Try removing 'const' from the constructor invocation.
class NetNinjaId extends StatelessWidget {
  const NetNinjaId({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'NetNinjaId',
      home: Scaffold(
        body: Padding(
          padding: const EdgeInsets.fromLTRB(0.0, 40.0, 0.0, 0.0),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: const [
              // Email
              Padding(
                padding: EdgeInsets.fromLTRB(50.0, 50.0, 0.0, 10.0),
                child: Row(children: const [
                  Icon(Icons.mail),
                  Text(
                    '[email protected]',
                    style: TextStyle(
                        color: Colors.amber,
                        fontSize: 20.0,
                        letterSpacing: 2.0),
                  ),
                ]),
              )
            ],
          ),
        ),
      ),
    );
  }
}

Full code here: https://pastebin.com/8aCkHNjN Error Screen shot: enter image description here

Things I tried:

Can anyone explain why this error is happening and what I can do to fix it. Thanks for your help in advance

Upvotes: 0

Views: 287

Answers (1)

Md. Yeasin Sheikh
Md. Yeasin Sheikh

Reputation: 63799

You need to remove const from

    body: Padding(
          padding: const EdgeInsets.fromLTRB(0.0, 40.0, 0.0, 0.0),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children:   [ //here

because Row doesn't use const constructor.

Upvotes: 1

Related Questions