android - 子元素的阴影在 flutter 中改变了一个 wrap 中的位置

标签 android iphone flutter listview shadow

我对 Wrap 的 child 的影子有疑问。

我设法快速地重新创建了它。

显然,滚动得越多,底部的阴影就会消失,并开始出现在每个项目的顶部,产生一种有点奇怪的效果。

子项的阴影如何保持在正确的位置?

在列表的底部,我又添加了几个按钮(但总是在 Wrap 之外),并且阴影转换正确。

编辑: 我添加示例代码以重现错误

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Hello World',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatelessWidget {
  final String title;

  const MyHomePage({@required this.title});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(title),
      ),
      body: Container(
          height: double.infinity,
          width: double.infinity,
          alignment: Alignment.center,
          child: ListView(
            children:[
                  new LayoutBuilder(
                      builder: (BuildContext context, BoxConstraints constraints) {
                        List<Widget> _list = List();
                        int _number_items = 30;
                        for(int a = 0; a < _number_items; a++){
                          _list.add(
                              Card(
                                elevation: 4,
                                child: Container(
                                  margin: EdgeInsets.all(10),
                                  width: 200,
                                  height: 200,
                                ),
                              )
                          );
                        }
                        for(int a = 0; a < _number_items; a++){
                          _list.add(
                              Container(
                                width: 400,
                                child: RaisedButton(
                                  onPressed: () {},
                                  child: Text(
                                    "Button in the Wrap ",
                                    style: TextStyle(color: colors.white),
                                  ),
                                  color: Colors.red,
                                ),
                              )
                          );
                        }
                        return Wrap(
                          children: _list,
                        );
                      }
                  ),
              RaisedButton(
                onPressed: () {},
                child: Text(
                  "Button outside the Wrap",
                  style: TextStyle(color: Colors.white),
                ),
                color: Colors.red,
              ),
              RaisedButton(
                onPressed: () {},
                child: Text(
                  "Button outside the Wrap",
                  style: TextStyle(color: Colors.white),
                ),
                color: Colors.red,
              ),
              RaisedButton(
                onPressed: () {},
                child: Text(
                  "Button outside the Wrap",
                  style: TextStyle(color: Colors.white),
                ),
                color: Colors.red,
              )
            ],
          )
      ),
    );
  }
}

例子:

enter image description here

最佳答案

将此添加到 ListView:

addRepaintBoundaries: false

关于android - 子元素的阴影在 flutter 中改变了一个 wrap 中的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63226853/

相关文章:

android - 如何在android中显示包含来自另一个 Activity 的用户名的欢迎消息?

iphone - 如何在 iOS 上获取当前位置?

ios - 导入仅适用于模拟器的 swift 框架

iphone - 无法打开可执行文件 - xcode

flutter - 如何在 Flutter 中实现此 CircularProgressIndicator?

flutter - Flutter-如何在调用某个操作按钮时重新加载整个页面(再次以其初始化状态重新加载小部件)?

java - OnClick ButterKnife,没有任何反应

android - 无法使用 setLayoutParams 更改 View 的宽度/高度

android - BroadcastReceiver 没有收到 BOOT_COMPLETED

image - SVG 图片正在 flutter 中返回黑色图像,尽管从评估中给出了彩色图像