2

I'm using flexibleSpace in SliverAppBar with floating: true, pinned: false, snap: true: When I scroll back up. It shows AppBar and flexibleSpace space https://flutter.github.io/assets-for-api-docs/assets/material/app_bar_floating_snap.mp4. But that I want is When user scroll bottom it should hide app bar and flexibleSpace and when user scroll to up it should show only appBar. Until scroll arrive to first of page and it should show flexibleSpace also.

4

1 回答 1

1

据我所知,SilverAppBar 中没有您想要的便利设置。

这可能不是最好的解决方案。但它适用于某些情况:

  1. 在 SliverAppBar() 中设置floating: truepinned: false(默认为 false)

  2. expandedHeight滚动位置控制

.

ScrollController _scrollController;
bool _top;
double _expandH;
double _collapseH;

@override
void initState() {
  _collapseH = 50;
  _expandH = 150;
  _top = false;
  _scrollController = ScrollController()..addListener(() {
    if(_scrollController.offset == 0 && !_top) {
      setState(() {
        _top = true;
        _scrollController.position.correctPixels(_expandH-_collapseH);
      });
    }else if(_top && _scrollController.offset > _expandH-_collapseH) {
      setState(() {
        _top = false;
        _scrollController.position.correctPixels(0);
      });
    }
  });
  super.initState();
}

...

CustomScrollView(
  controller: _scrollController,
  slivers: [
    SliverAppBar(
      floating: true,
      // pinned: false,
      expandedHeight:_top ? _expandH: _collapseH,
      ...
于 2020-10-23T13:43:27.643 回答