文章目录

Flutter BouncingScrollPhysics回弹无效、回弹不会恢复原位

由 月林 发布
  | 1245 次浏览

ListView内容不足以撑满全屏的情况下:

ListView.builder(
  physics: AlwaysScrollableScrollPhysics(parent: BouncingScrollPhysics()), // ListView内容不足也能搞出回弹效果
  ...
);

如果是普通的Scaffold套SingleChildScrollView,而内容却不是ListView等滚动组件
例如Column支撑不满剩余空间:(暂时没想到更好的解决方式)

Scaffold(
  appBar: AppBar(),
  body: SingleChildScrollView(
    physics: AlwaysScrollableScrollPhysics(parent: BouncingScrollPhysics()), // 添加这一行
    child: Container(
      // 添加这一行,使得SingleChildScrollView填充满;还解决了滑动回弹不会回到原位的问题
      constraints: BoxConstraints(
          minHeight: MediaQuery.of(context).size.height - kToolbarHeight - MediaQuery.of(context).padding.top),
      child: Column(
        children: [...]
      ),
    ),
  ),
),

NestedScrollView套SingleChildScrollView套Column就正常。

如果是CustomScrollView,可以尝试使用SliverFillRemaining充满剩余大小


版权属于:月琳cc
本文链接:https://kerrinz.com/archives/186.html
作品采用《知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议》进行许可,转载请务必注明出处!

暂无评论

发表评论