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

问题描述 投票:0回答:1

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

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

}

flutter dart flutter-layout flutter-animation
1个回答
1
投票

因为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
                    ),
                  )
                ],
© www.soinside.com 2019 - 2024. All rights reserved.