Тень дочерних элементов меняет положение внутри обтекания во флаттере. - PullRequest
3 голосов
/ 03 августа 2020

У меня проблема с тенью дочерних элементов Wrap.

Мне удалось быстро его воссоздать.

Видно, чем больше вы прокручиваете, тем больше исчезает тень внизу и начинает выступать вверху каждого элемента, создавая несколько странный эффект.

Как тень дочерних элементов могла оставаться в правильном положении?

Внизу списка , Я добавил еще несколько кнопок (но всегда за пределами Wrap), и тень отбрасывается правильно.

Edit: я добавляю образец кода для воссоздания ошибки

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

Пример:

введите описание изображения здесь

1 Ответ

3 голосов
/ 03 августа 2020

Добавьте это к ListView:

addRepaintBoundaries: false
...