gpt4 book ai didi

google-maps - 当触摸集中在另一个小部件上时如何防止 SliverAppBar 滚动

转载 作者:IT王子 更新时间:2023-10-29 06:57:18 25 4
gpt4 key购买 nike

我有一个 SliverAppBar,我想在用户向下滚动页面时隐藏它。问题是我有一个谷歌地图小部件导致应用程序栏也移动,而我只希望它仅在我的触摸离开谷歌地图时移动。有没有办法prevent this

@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
backgroundColor: Colors.transparent,
elevation: 5.0,
pinned: false,
snap: false,
floating: false,
expandedHeight: 200,
flexibleSpace: FlexibleSpaceBar(
background: Image.asset(
'assets/events/city.jpeg',
fit: BoxFit.cover,
),
),
),
SliverFillRemaining(
child: SingleChildScrollView(
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(16.0),
child: Container(
height: 200,
width: double.infinity,
child: GoogleMap(
initialCameraPosition:
CameraPosition(target: LatLng(50.0, 50.0)),
onMapCreated: (controller) {
setState(() {
_googleMapController = controller;
});
},
),
),
)
],
),
),
)
],
),
));
}

最佳答案

我发现将 gestureRecognizer 属性添加到 GoogleMap 并传入 VerticalDragRecognizer 类型的工厂可以防止 SliverAppBar 滚动。它也适用于您想要为您的应用程序提供的任何类型的滚动。参见 this在 50 分钟左右了解更多信息。

SliverFillRemaining(
child: SingleChildScrollView(
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(16.0),
child: Container(
height: 200,
width: double.infinity,
child: GoogleMap(
gestureRecognizers: Set()..add(Factory<VerticalDragGestureRecognizer>(
() => VerticalDragGestureRecognizer()
)),
scrollGesturesEngabled: true,
initialCameraPosition:
CameraPosition(target: LatLng(50.0, 50.0)),
onMapCreated: (controller) {
setState(() {
_googleMapController = controller;
});
},
),
),
)
],
),
),
)

关于google-maps - 当触摸集中在另一个小部件上时如何防止 SliverAppBar 滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55873554/

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