我在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])],你能帮我解决这个问题吗?
发布于 2021-02-07 02:11:47
构造函数后面缺少一个分号
ReusableScreen({
    @required this.jour,
    @required this.heure,
});https://stackoverflow.com/questions/66080166
复制相似问题