flutter - 错误:在此之前应为“{”。@覆盖
问题描述
我在颤振代码中遇到了一个我不理解的错误。
这是我的代码:
import 'package:flutter/material.dart';
class ReusableScreen extends StatelessWidget{
final List <String> dirs=['11', '12', '13', '14', '21', '22', '23', '24', '31', '32', '33', '34', '41', '42', '43', '44'];
final String jour;
final String heure;
ReusableScreen({
@required this.jour,
@required this.heure,
})
@override
Widget build(BuildContext context) {
return ListView(
scrollDirection: Axis.horizontal,
children: [for (var temp in dirs) AssetImage('assets/'+this.jour+"/"+this.heure+"/"+this.dirs[temp])],
);
}
}
这是完整的错误信息:
lib/wid.dart:14:3: Error: Expected '{' before this.
@override
^
lib/wid.dart:18:101: Error: A value of type 'String' can't be assigned to a variable of type 'int'.
children: [for (var temp in dirs) AssetImage('assets/'+this.jour+"/"+this.heure+"/"+this.dirs[temp])],
^
lib/wid.dart:18:41: Error: A value of type 'AssetImage' can't be assigned to a variable of type 'Widget'.
- 'AssetImage' is from 'package:flutter/src/painting/image_resolution.dart' ('/C:/flutter/packages/flutter/lib/src/painting/image_resolution.dart').
- 'Widget' is from 'package:flutter/src/widgets/framework.dart' ('/C:/flutter/packages/flutter/lib/src/widgets/framework.dart').
children: [for (var temp in dirs) AssetImage('assets/'+this.jour+"/"+this.heure+"/"+this.dirs[temp])],
你能帮我找出问题吗?
解决方案
你在构造函数之后缺少一个分号
ReusableScreen({
@required this.jour,
@required this.heure,
});
推荐阅读
- python - 如何将二维数组的特定部分向上或向下移动?
- reactjs - React Bootstrap 应用程序未运行
- raspberry-pi - 后端终止或断开连接。使用“停止/重新启动”在 Raspberry Pi 上重新启动
- python - Python中制表符和空格的使用不一致
- python - VS Code 没有识别同一目录中的文件
- python - 文件路径中的空格:///
- android - 选择菜单选项时出现 NonSDKApi 违规
- node.js - MongoError:使用 Docker 容器的 node.js 应用程序的身份验证失败
- python - 如何在带有栅格数据集的python中循环
- flutter - 我的对象响应其他对象的变化。如何更改单个按钮的颜色?