VeryGoodOpenSource/very_good_analysis

Getting `prefer_const_literals_to_create_immutables` when using `UserAccountsDrawerHeader`.

tirth-stasis opened this issue ยท 7 comments

Describe the bug
Getting prefer_const_literals_to_create_immutables when using UserAccountsDrawerHeader.

To Reproduce

const UserAccountsDrawerHeader(
  accountName: Text('Test'),
  accountEmail: Text('Test'),
)

Expected behavior
It shouldn't show this warning.

Screenshots
Screenshot at 2021-06-09 23-22-49

Additional context
https://dart-lang.github.io/linter/lints/prefer_const_literals_to_create_immutables.html

Hi @tirth-stasis ๐Ÿ‘‹
Thanks for opening an issue!

I believe this is because you can make the entire Drawer const:

const Drawer(
 child: SingleChildScrollView(...),
);

Hope that helps ๐Ÿ‘

Hey!

I'm not able to make entire Drawer a const. Column doesn't have a const constructor.

Eventually I would replace Test with a runtime value. So I would remove const from UserAccountsDrawerHeader. But right now I don't have real-data so I ended up using literals.

Replaced Test with DateTime.now().toString() for now. Can I close this?

Sounds good, yeah definitely. Thanks!

Hey!

I'm not able to make entire Drawer a const. Column doesn't have a const constructor.

Ah I missed that you should be able to specify the children as a const list:

Column(
  children: const [
    UserAccountsDrawerHeader(),
  ],
);

ah you're right! cheers, thanks!