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

标签 flutter dart flutter-layout flutter-animation

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

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

}

最佳答案

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

关于flutter - 无法将参数类型 'BoxShadow'分配给参数类型 'List<BoxShadow>',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59126655/

相关文章:

flutter - 如何在Flutter中进行自定义边框设计?

flutter - Flutter 中是否有打开内置蓝牙菜单的 Android(和 iOS)的方法

dart - 淡化边缘 ListView - Flutter

android - 使用 flutter 中的手势检测器导航到不同页面时,黑屏 flutter 。说多个英雄共享同一个标签

flutter - 使用其有状态小部件访问状态类的方法?

flutter - 在 flutter 中更新现有 StatefulWidget 类的小部件

flutter - 如何在步骤进度中添加圆形边框

flutter - 如何找到 flutter 中的两个日期之间的差异?

使用 Dart 登录 Facebook 和 Google+

dart - Dart 的静态方法和类方法的区别