Prefer const literals as parameters of constructors on @immutable classes

Viewed 429

I am following the example of this tutorial.

If I want to add two text components to a children array and I get the title warning.

For example:

Widget titleSection = Container(
  child: Row(
    //need to expand the rows on the column
    children: [
      Expanded(
        child: Column(
          children: [
            const Text(
              'Hello1',
            ),
            const Text(
              'Hello2',
            ),
          ],
      )         
    ],
  ),
);

What am I doing wrong?

1 Answers

In your case it should be

    Widget titleSection = Container(
      child: Row(
        //need to expand the rows on the column
        children: [
          Expanded(
            child: Column(
              children: const [
                Text(
                  'Hello1',
                ),
                Text(
                  'Hello2',
                ),
              ],
            ),
          )
        ],
      ),
    );
Related