Flutter - 在 CustomScrollView 内的某些容器上进行手势时防止滚动

问题描述 投票:0回答:1
child: CustomScrollView(
  slivers: [
    SliverToBoxAdapter(
      child: Padding(
        padding: const EdgeInsets.only(right: 2.5, left: 2.5),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            TestingWIdget(),
            Container(height: 300, width: 300, child: GoogleMapWidget()), // when user touching this, i want to prevent from the page scrolling
            SizedBox(height: 30),
            SizedBox(height: 40),
          ],
        ),
      ),
    )
  ],
),

基本上,当用户在

Container
上执行某些操作时,我想防止脚手架滚动,因为它有
GoogleMap
。当用户做某事时,地图也会移动。我不想这样做。我只能找到有关
IgnorePointer
小部件的信息,但它只是忽略了触摸
GooglaMap()

当用户在某个小部件上执行某些操作时,有什么方法可以防止滚动吗?

flutter
1个回答
0
投票

使用侦听器跟踪用户是否正在与

GoogleMapWidget
交互,以相应地更新
CustomScrollView
的物理特性。

class _MyWidgetState extends State<MyWidget> {
  bool _isInteractingMap = false;

  @override
  Widget build(BuildContext context) {
    return CustomScrollView(
      physics: _isInteractingMap
          ? const NeverScrollableScrollPhysics()
          : const AlwaysScrollableScrollPhysics(),
      slivers: [
        SliverToBoxAdapter(
          child: Listener(
            onPointerDown: (_) {
              setState(() {
                _isInteractingMap = true;
              });
            },
            onPointerUp: (_) {
              setState(() {
                _isInteractingMap = false;
              });
            },
            child: Container(
              height: 300,
              width: 300,
              child: GoogleMapWidget(),
            ),
          ),
        )
      ],
    );
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.