【问题标题】:My sliverappbar doesn't expand when i start scrolling back up, it only expands when i get to the top of the list again当我开始向上滚动时,我的 sliverappbar 不会展开,它只会在我再次到达列表顶部时展开
【发布时间】:2019-08-20 10:54:14
【问题描述】:

我有一个带有 sliverappbar 的nestedsrcollview,当我按预期向下滚动时它会缩小,但是当我向上滚动时应用程序栏不会展开,直到我到达顶部(到列表中的第一项)并且我在查看文档中的示例后知道这是不对的。它应该在您开始滚动时展开或收缩,而不是在您完成向上或向下滚动时

class App extends StatefulWidget {
  @override
  _AppState createState() => _AppState();
}

class _AppState extends State<App>
    with SingleTickerProviderStateMixin {
  final List<Tab> myTabs = <Tab>[
    Tab(
      child: Container(
        child: Icon(//icon),
      ),
    ),
    Tab(
      child: Container(
        child: Icon(//icon),
      ),
    ),
    Tab(
      child: Container(
        child: Icon(
          //icon,
        ),
      ),
    ),
    Tab(
      child: Container(
        child: Icon(
          //icon,
        ),
      ),
    ),
  ];

  final List tabChildren = [
    Child1(

      key: PageStorageKey<String>('1'),
    ),
    Child2(
      key: PageStorageKey<String>('2'),
    ),
    Child3(
      key: PageStorageKey<String>('3'),
    ),
   Child4(
      key: PageStorageKey<String>('4'),
    ),
  ];




  @override
  void initState() {
    super.initState();
    _tabController = TabController(vsync: this, length: myTabs.length)

  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: false,
      body: NestedScrollView(

        headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
          return <Widget>[
            new SliverAppBar(


              title: Text(
                'Dummy text',
                style: Theme.of(context)
                    .textTheme
                    .title
                    .copyWith(color: Colors.white),
              ),
              pinned: true,
              floating: true,

              forceElevated: innerBoxIsScrolled,
              bottom: TabBar(

                controller: _tabController,
                tabs: myTabs,
              ),
            ),

          ];
        },

        body: TabBarView(
          controller: _tabController,
          children: [

            SafeArea(
              top: false,
              bottom: false,
              child: 

                tabChildren[0], // listView

            ),
            SafeArea(
              top: false,
              bottom: false,
              child: 

                tabChildren[1], // listView


            ),
            SafeArea(
              top: false,
              bottom: false,
              child: 
                tabChildren[2], // listView


            ),
            SafeArea(
              top: false,
              bottom: false,
              child:  

              tabChildren[3], // listView

            ),
          ],
        ),
      ),

    );
  }
}

【问题讨论】:

    标签: flutter flutter-sliver


    【解决方案1】:

    设置以下属性。

    snap: true,
    floating: true
    

    例子:

    new SliverAppBar(
    
                  title: Text(
                    'Dummy text',
                    style: Theme.of(context)
                        .textTheme
                        .title
                        .copyWith(color: Colors.white),
                  ),
                  floating: true,
                  snap: true,
                  forceElevated: innerBoxIsScrolled,
                  bottom: TabBar(
    
                    controller: _tabController,
                    tabs: myTabs,
                  ),
                ),
    

    【讨论】:

      【解决方案2】:

      两个属性控制 SliverAppBar 的动作。 pinned & floating

      您已将pinnedfloating 都设置为true,即使没有错,当两者都设置为true 时,您永远看不到实际的Sliver Motion。

      要真正获得您所谓的“扩展效果”,只需将 floating 设置为 true。如果这不是您要查找的内容,则可能是关于您的预期输出的图像或 GIF 将有助于实现正确的代码。

      【讨论】:

      • 浮动和固定设置为 true 的示例是我想要的行为,但在我的情况下,应用栏在到达列表项 1 之前不会展开
      • 您发送的链接中是否正在尝试实现类型4?还是哪一个?可以分享您应用的工作 GIF 吗?
      • 是的,类型 4。它的浮动和固定属性和我的一样
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-19
      相关资源
      最近更新 更多