在Flutter中,一个List可以同时被两个AnimatedListView使用。你需要将该List作为两个AnimatedListView的数据源,并将这两个AnimatedListView的滚动控制器分别绑定到同一个ScrollController。这样,当一个AnimatedListView滚动时,另一个AnimatedListView也会同时滚动。

以下是示例代码:

List<String> items = ['Item 1', 'Item 2', 'Item 3', 'Item 4'];

ScrollController _scrollController = ScrollController();

@override
Widget build(BuildContext context) {
  return Scaffold(
    body: Column(
      children: [
        Expanded(
          child: AnimatedListView(
            controller: _scrollController,
            items: items,
            itemBuilder: (context, index, animation) {
              return SizeTransition(
                sizeFactor: animation,
                child: ListTile(
                  title: Text(items[index]),
                ),
              );
            },
          ),
        ),
        Expanded(
          child: AnimatedListView(
            controller: _scrollController,
            items: items,
            itemBuilder: (context, index, animation) {
              return SizeTransition(
                sizeFactor: animation,
                child: ListTile(
                  title: Text(items[index]),
                ),
              );
            },
          ),
        ),
      ],
    ),
  );
}

在上述代码中,我们创建了一个名为items的List,并使用该List作为两个AnimatedListView的数据源。我们还创建了一个名为_scrollController的ScrollController,并将其绑定到两个AnimatedListView的滚动控制器中。

最后,我们在Column中嵌套两个Expanded,并将两个AnimatedListView放置在其中,以便它们可以占据整个屏幕。

在Flutter中一个List可以同时被两个AnimatedListView使用吗?该如何做呢?

原文地址: https://www.cveoy.top/t/topic/sHv 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录