即使值类型没有错误(无效的常数值),也存在错误
List<MaterialColor?> changeColor = [
Colors.red,
Colors.blue,
Colors.yellow,
Colors.green,
Colors.pink,
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'Mohammed is coming back ',
style: TextStyle(
color: changeColor[_counter],
fontSize: 22,
fontWeight: FontWeight.bold,
),
),
我列出了一个由一组颜色组成的列表,我想将其赠送给颜色
List<MaterialColor?> changeColor = [
Colors.red,
Colors.blue,
Colors.yellow,
Colors.green,
Colors.pink,
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'Mohammed is coming back ',
style: TextStyle(
color: changeColor[_counter],
fontSize: 22,
fontWeight: FontWeight.bold,
),
),
I made a list consisting of a set of colors and I want to give it to the color but it keeps giving me this error, even though I gave the list type the same as the color type
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
_counter
值将更改并进入读取时间。这就是为什么文本
小部件不能成为const的原因。从文本中删除const。您可以更多地了解
_counter
value will change and get on read time. That's whyText
widget can not be const. Remove const from Text.You can more about