我的应用程序的 Sliver 应用程序栏已包含 CustomScrollView 小部件。上面还有其他的裂片。我只需要停止 Sliver 应用栏上的滚动。当我触摸 Sliver 时,它会滚动整个页面。添加 NeverScrollableScrollPhysics() 后整个页面无法滚动。但我只需要停止SliverAppBar。
body: CustomScrollView(
controller: _scrollController,
slivers: <Widget>[
SliverAppBar(
systemOverlayStyle: SystemUiOverlayStyle.light,
backgroundColor: Theme.of(context).backgroundColor,
elevation: 1.0,
expandedHeight:
kIsWeb ? 0 : widthHeight * kProductDetail.height,
pinned: true,
floating: false,
leading: Padding(
padding: const EdgeInsets.all(8),
child: CircleAvatar(
backgroundColor: Theme.of(context)
.primaryColorLight
.withOpacity(0.7),
child: IconButton(
icon: Icon(
Icons.close,
color: Theme.of(context).primaryColor,
),
onPressed: () {
context
.read<ProductModel>()
.clearProductVariations();
Navigator.pop(context);
},
),
),
),
actions: <Widget>[
if (widget.isLoading != true)
HeartButton(
product: product,
size: 20.0,
color: Theme.of(context).primaryColor,
),
Padding(
padding: const EdgeInsets.all(12),
child: CircleAvatar(
backgroundColor: Theme.of(context)
.primaryColorLight
.withOpacity(0.7),
child: IconButton(
icon: const Icon(Icons.more_vert, size: 19),
color: Theme.of(context).primaryColor,
onPressed: () => ProductDetailScreen.showMenu(
context,
widget.product,
isLoading: widget.isLoading,
),
),
),
),
],
flexibleSpace: kIsWeb
? const SizedBox()
: ProductImageSlider(
product: product,
onChange: (index) => setState(() {
_selectIndex = index;
}),
),
),
SliverList(
delegate: SliverChildListDelegate(
<Widget>[
const SizedBox(height: 2),
if (kIsWeb)
ProductGallery(
product: widget.product,
selectIndex: _selectIndex,
),
Padding(
padding: const EdgeInsets.only(
top: 8.0,
bottom: 4.0,
left: 15,
right: 15,
),
child: product.type == 'grouped'
? const SizedBox()
: ProductTitle(product),
),
],
),
),
if (Services().widget.enableShoppingCart(
product.copyWith(isRestricted: false)))
renderProductInfo(),
if (!Services().widget.enableShoppingCart(
product.copyWith(isRestricted: false)) &&
product.shortDescription != null &&
product.shortDescription!.isNotEmpty)
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 15.0),
child: ProductShortDescription(product),
),
),
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.symmetric(
// horizontal: 15.0,
vertical: 8.0,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 15.0,
),
child: Column(
children: [
Services().widget.renderVendorInfo(product),
ProductDescription(product),
if (kProductDetail.showProductCategories)
ProductDetailCategories(product),
if (kProductDetail.showProductTags)
ProductTag(product),
Services()
.widget
.productReviewWidget(product.id!),
],
),
),
if (kProductDetail
.showRelatedProductFromSameStore &&
product.store?.id != null)
RelatedProductFromSameStore(product),
if (kProductDetail.showRelatedProduct)
RelatedProduct(product),
const SizedBox(height: 50),
],
),
),
),
],
),
我只是想在触摸 SliverAppBar 时停止整个滚动。
您可以添加
NeverScrollableScrollPhysics
来实现此目的。
...
CustomScrollView(
controller: _scrollController,
physics: NeverScrollableScrollPhysics(),
..
更多信息请访问 flutter 文档
使用嵌套滚动视图并设置固定为 true,这样应用栏不会滚动,但主体会滚动,并且嵌套滚动视图中有 3 个参数有助于以不同方式设置滚动。
或在 YouTube 上查看此视频,它会对您有所帮助 https://youtu.be/xzPXqQ-Pe2g
Waste os many time, but finally found a solution. Enjoy, guys)
child: Scrollbar(
notificationPredicate: (ScrollNotification notification) {
return notification.metrics.pixels > 100.h;
},
child: CustomScrollView(
slivers: [])...