当触摸聚焦于另一个小部件时,如何防止SliverAppBar滚动

问题描述 投票:0回答:1

当用户在页面上向下滚动时,我想要隐藏一个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;
                      });
                    },
                  ),
                ),
              )
            ],
          ),
        ),
      )
    ],
  ),
));
}
google-maps dart flutter uiscrollview
1个回答
0
投票

我发现将gestureRecognizer属性添加到GoogleMap并传入VerticalDragRecognizer类型的Factory允许它阻止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;
                  });
                },
              ),
            ),
          )
        ],
      ),
    ),
  )
© www.soinside.com 2019 - 2024. All rights reserved.