相关疑难解决方法(0)

带TabBar的SliverAppBar

如何在Flutter中将TabBar添加到SliverAppBar?到目前为止,当我bottom向SliverAppBar 添加a 时,title会固定到这些选项卡,而我希望它位于这些选项卡上方。
有任何想法吗?

屏幕

我的代码:

class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateMixin{
  TabController controller;


  @override
  void initState() {
    super.initState();
    controller = new TabController(length: 3, vsync: this);
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: new CustomScrollView(
        slivers: <Widget>[
          new SliverAppBar(
            pinned: true,
            flexibleSpace: new FlexibleSpaceBar(
              title: new Text("Some title"),
            ),
            expandedHeight: 160.0,
            bottom: new TabBar(tabs: [
              new Tab(text: 'Tab 1'),
              new Tab(text: 'Tab 2'),
              new Tab(text: 'Tab 3'),
            ],
            controller: controller,
            ),
          ),
          new SliverList( …
Run Code Online (Sandbox Code Playgroud)

flutter

12
推荐指数
1
解决办法
5026
查看次数

将TabBar像SliverAppBar一样隐藏

因此,网络上有很多示例,您可以SliverAppBar在滚动条上使用隐藏的内容,并且TabBar仍在下面显示。我找不到反过来做的任何事情:当我向上滚动时,我只想隐藏TabBarAppBar始终保持持续显示。有谁知道如何实现这一目标?

这是一个隐藏AppBar的示例(这不是我想要的,只是有助于更好地了解我想要的东西)。

更新

到目前为止,这是我尝试过的,并且我认为它可以工作,但是问题是我无法AppBarPositioned野外获得正确的高度(例如,iPhone X的高度更大并且与标签栏重叠)。

// this sliver app bar is only use to hide/show the tabBar, the AppBar  
// is invisible at all times. The to the user visible AppBar is below
return Scaffold(
  body: Stack(
    children: <Widget>[
      NestedScrollView(
        headerSliverBuilder:
            (BuildContext context, bool innerBoxIsScrolled) {
          return <Widget>[
            SliverAppBar(
              floating: true,
              snap: true,
              pinned: false,
              bottom: TabBar(
                tabs: [
                  Tab(
                    child: Text(
                      "1",
                      textAlign: TextAlign.center,
                    ), …
Run Code Online (Sandbox Code Playgroud)

dart flutter

7
推荐指数
1
解决办法
449
查看次数

标签 统计

flutter ×2

dart ×1