首页 > 解决方案 > 错误:在此之前应为“{”。@覆盖

问题描述

我在颤振代码中遇到了一个我不理解的错误。

这是我的代码:

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])],

你能帮我找出问题吗?

标签: flutterdart

解决方案


你在构造函数之后缺少一个分号

ReusableScreen({
    @required this.jour,
    @required this.heure,
});

推荐阅读