Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prefer const literals as parameters of constructors on @immutable classes in android studio

In the following code, I'm getting inspection warning with 'prefer const literals as parameters of constructors on @immutable classes' and it's annoying. What should I do to make it go away?

screenshot from ide

Container(
        margin: const EdgeInsets.all(20),
        width: double.infinity,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            TextField(
              decoration: InputDecoration(
                  border: OutlineInputBorder(),
                  hintText: 'Enter a search term'),
            ),
            Text("these are the search results", textAlign: TextAlign.left),
          ],
        ),
      )

I have tried to make every constructor call 'const' with no avail.

Container(
        margin: const EdgeInsets.all(20),
        width: double.infinity,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            const TextField(
              decoration: const InputDecoration(
                  border: const OutlineInputBorder(),
                  hintText: 'Enter a search term'),
            ),
            const Text("these are the search results", textAlign: TextAlign.left),
          ],
        ),
      ),
like image 349
Shawn McCool Avatar asked Dec 09 '22 23:12

Shawn McCool


1 Answers

Just mark the list as const:

Container(
    margin: const EdgeInsets.all(20),
    width: double.infinity,
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: const [
        TextField(
          decoration: InputDecoration(
              border: OutlineInputBorder(),
              hintText: 'Enter a search term'),
        ),
        Text("these are the search results", textAlign: TextAlign.left),
      ],
    ),
  ),
like image 83
mmcdon20 Avatar answered Jan 25 '23 16:01

mmcdon20