flutter - 滚动 TabBarView 子项时使 SliverAppBar 可滚动

标签 flutter flutter-layout

我有一个带底部导航的主屏幕,它由两个项目组成,它们都在内部有 ListView 和无限列表,我希望 SliverAppBar 在用户在其中一个列表中滚动时可以滚动。 这是我目前所拥有的

class HomeScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
        length: 2,
        child: new Scaffold(
          body: CustomScrollView(
            slivers: <Widget>[
              SliverAppBar(
                snap: false,
                floating: false,
                pinned: true,
                expandedHeight: 160.0,
                flexibleSpace: FlexibleSpaceBar(
                  title: Text('Title'),
                ),
              ),
              SliverFillRemaining(
                child: TabBarView(
                  children: <Widget>[Items(), Activities()], //THESE HAVE LIST VIEW IN EACH 
                ),
              )
            ],
          ),
        ));
  }
}

这里是 TabBarView 子项之一的代码。

class Items extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    List<Widget> itemsWidgets = List.from(getItemsList()
        .map((Item item) => createItemWidget(context, item)));

    return Scaffold(
      body: Center(
        child: ListView(
          children: itemsWidgets,
        ),
      ),
    );
  }

  ListTile createItemWidget(BuildContext context, Item item) {
    return new ListTile(
      title: Text(item.sender.name),
      subtitle: Text('10:30 am'),
    );
  }
}

当用户在其中一个列表中滚动时,SilverAppBar 如何滚动?任何帮助/建议将不胜感激。

最佳答案

使用NestedScrollView . api里面有例子

关于flutter - 滚动 TabBarView 子项时使 SliverAppBar 可滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60967806/

相关文章:

flutter - 如何在Flutter中执行分页

flutter - 如何在单行小部件 flutter 上左、中、右对齐小部件

flutter - 如何在flutter中实现stories进度 View

flutter - Flutter bool 变量未更新

Flutter awesome 通知点击打开特定页面

ios - CupertinoTextField 中的 Flutter 文本验证

node.js - 使用 IO 套接字和 nodejs 在 flutter 中推送通知

flutter - 来自顶部()的图像和图像下方带有文本的框

flutter - Flutter 中 SliverList 与 ListView 的区别

flutter - 有没有办法在 Flutter 上添加两个不同颜色的 Iphone x SafeArea