无法将参数类型'BoxShadow'分配给参数类型'List <BoxShadow>'

时间:2019-12-01 14:50:06

标签: flutter dart flutter-layout flutter-animation

我正在尝试建立一个自定义列表项。当我尝试为列表项分配框半径时,遇到以下语法错误:

**The argument type 'BoxShadow' can't be assigned to the parameter type 'List<BoxShadow>'.**

似乎我无法为列表分配阴影。我是flutter的新手,有没有一种方法可以将自定义框阴影添加到AnimatedList()的列表项中。我提供了以下代码:

Widget _buildItem(UserModel user, [int index]) {
return Container(
  padding: EdgeInsets.all(8.0),
  margin: EdgeInsets.symmetric(horizontal: 10.0, vertical: 6.0),
  decoration: BoxDecoration(
    color: Colors.grey[50],
    borderRadius: BorderRadius.all(Radius.circular(5.0)),
    boxShadow: BoxShadow(
      blurRadius: 5.0
    )
  ),
  child: Row(
    children: <Widget>[
      InkWell(
        child: CircleAvatar(
          radius: 30.0,
          backgroundImage: NetworkImage(user.photo, scale: 64.0),
        ),
        onLongPress: index != null ? () => deleteUser(index) : null,
      )
    ],
  ),
);

}

1 个答案:

答案 0 :(得分:2)

因为boxShadow必须包含列表[],

您的解决方法是

...
         boxShadow: [
                  BoxShadow(
                    color: Colors.amber.shade100,
                    blurRadius: 15.0,
                    // has the effect of softening the shadow
//                    spreadRadius: 2.0,
                    // has the effect of extending the shadow
                    offset: Offset(
                      1.0, // horizontal, move right 10
                      5.0, // vertical, move down 10
                    ),
                  )
                ],