在下面的代码中,我收到了一个检查警告,“prefer const literal as parameters of constructors on @immutable classes”,这很烦人。我该怎么做才能让它消失呢?
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),
],
),
)
我试过让每个构造函数都调用'const',但没有用。
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),
],
),
),
1条答案
按热度按时间bmp9r5qi1#
只需将列表标记为const: