Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prefer const literals to create immutables classes

Tags:

flutter

I get an error :

prefer_const_literals_to_create_immutables

on this widget:

 child: Column(
     children: <Widget>[
         Hyperlink('https://t.me/egorka', 'chat with me'),
     ],
 ),

where class Hyperlink is defined like:

class Hyperlink extends StatelessWidget {
  const Hyperlink(this._url, this._text);

  final String _url;
  final String _text;

I can't figure out how to change the code to get rid of it?

like image 573
rozerro Avatar asked Dec 24 '19 22:12

rozerro


3 Answers

Your code is absolutely fine .But remove the const keyword from the constructor.

like image 173
Guru Prasad mohapatra Avatar answered Nov 13 '22 22:11

Guru Prasad mohapatra


jump to file analysis_options.yaml add this code prefer_const_literals_to_create_immutables: false below property rules : then Ctrl+s



example :
rules:
prefer_const_literals_to_create_immutables: false
prefer_typing_uninitialized_variables: false
prefer_const_constructors: false
file_names: false
like image 40
Nashwan Avatar answered Nov 13 '22 21:11

Nashwan


another solution

child: Column(
     children: <Widget> const[
         Hyperlink('https://t.me/egorka', 'chat with me'),
     ], <enter code here>
 ),
like image 26
K4RLUKH4N Avatar answered Nov 13 '22 20:11

K4RLUKH4N