gpt4 book ai didi

Flutter CustomScrollView 在没有足够的项目时滚动

转载 作者:行者123 更新时间:2023-12-03 17:29:25 26 4
gpt4 key购买 nike

使用 slivers 和 sliver appbar 时出现滚动问题。当视频中不需要滚动时,如何防止 ScrollView 滚动。如果有足够的滚动项,它应该滚动(这很好用)

我关注了这个中等帖子。你可以看到他有同样的问题。
https://medium.com/@diegoveloper/flutter-collapsing-toolbar-sliver-app-bar-14b858e87abe

https://youtu.be/l1EwM9GAfxw

class HomeScreen extends StatelessWidget{
@override
Widget build(BuildContext context) {
return Scaffold(
body: NestedScrollView(
headerSliverBuilder: (context, innerBoxIsScrolled) => [
SliverAppBar(
brightness: Brightness.dark,
backgroundColor: Colors.amber.withOpacity(0.5),
expandedHeight: 166,
flexibleSpace: FlexibleSpaceBar(
collapseMode: CollapseMode.pin,
background: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: 80,
width: 80,
child: Placeholder(),
),
Row(
children: [
Text(
'sdalkf',
),
],
),
],
),
),
),
),
SliverPersistentHeader(
delegate: SliverAppBarDelegate(
MediaQuery.of(context).padding.top,
Container(
color: Colors.amber.withOpacity(0.5),
child: SafeArea(
bottom: false,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('sdfaklladsjfkladslkf\nsadjflkasjklfs\nsdkjlfjlkadslfjk'),
],
),
),
),
),
pinned: true,
),
],
body: GridView.builder(
itemCount: 3,
padding: EdgeInsets.zero,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, childAspectRatio: 0.68),
itemBuilder: (context, index) => Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: Container(
color: Colors.black54,
),
),
),
),
);
}
}
class SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
final Widget child;
final double topSafeArea;

_SliverAppBarDelegate(this.topSafeArea, this.child);

@override
double get minExtent => 105 + topSafeArea;

@override
double get maxExtent => 105 + topSafeArea;

@override
Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) {
return Container(
child: child,
);
}

@override
bool shouldRebuild(_SliverAppBarDelegate oldDelegate) {
return false;
}
}

相关:

Flutter SliverAppBar with Tabs overlays content

上面的链接不是解决方案而是临时修复

最佳答案

套装physics ScrollView 到 AlwaysScrollableScrollPhysics 的行为
从文档:

/// Scroll physics that always lets the user scroll.
///
/// This overrides the default behavior which is to disable scrolling
/// when there is no content to scroll. It does not override the
/// handling of overscrolling.

关于Flutter CustomScrollView 在没有足够的项目时滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57371095/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com