0

我在单个子滚动视图中的应用程序中使用谷歌地图插件以及一些列表和其他小部件。问题是当我向下或向上滚动时,谷歌地图小部件粘在顶部或底部与其他小部件重叠,如下所示。我试图通过 github 和 stackoverflow 上的现有问题,但找不到任何解决方案。如果有人遇到同样的问题或有解决方案,请帮助我。

问题-> https://gifyu.com/image/YVZx

这是重现相同问题的代码。

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  Completer<GoogleMapController> _controller = Completer();

  static final CameraPosition _kGooglePlex = CameraPosition(
    target: LatLng(37.42796133580664, -122.085749655962),
    zoom: 14.4746,
  );

  static final CameraPosition _kLake = CameraPosition(
      bearing: 192.8334901395799,
      target: LatLng(37.43296265331129, -122.08832357078792),
      tilt: 59.440717697143555,
      zoom: 19.151926040649414);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('iOS Map'),
      ),
      body: SingleChildScrollView(
        child: Column(
          children: [
            ListView.builder(
                itemCount: 20,
                shrinkWrap: true,
                physics: NeverScrollableScrollPhysics(),
                itemBuilder: (ctx, index) {
                  return Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Card(
                      child: Text('Test item $index'),
                    ),
                  );
                }),
            SizedBox(
              height: 250,
              child: GoogleMap(
                mapType: MapType.hybrid,
                initialCameraPosition: _kGooglePlex,
                onMapCreated: (GoogleMapController controller) {
                  _controller.complete(controller);
                },
              ),
            ),
            ListView.builder(
                itemCount: 50,
                shrinkWrap: true,
                physics: NeverScrollableScrollPhysics(),
                itemBuilder: (ctx, index) {
                  return Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Card(
                      child: Text('Test item $index'),
                    ),
                  );
                }),
          ],
        ),
      ),
    );
  }
}
4

2 回答 2

1

这是一个与 Flutter 引擎有关的问题,而不是 Maps 问题。

这是问题链接 https://github.com/flutter/flutter/issues/76097

此问题已在最新的 Flutter 2.2 版本中修复。

所以请升级到最新的flutter。

于 2021-05-24T03:58:36.820 回答
0

我已经修改了你的一些代码片段,而不是添加到 ScrollView 中,将它添加到 ListView 上然后它会解决你的问题,

@overrideWidget build(BuildContext context) {return Scaffold(
appBar: AppBar(
  title: Text('iOS Map'),
),
body: ListView(
    children: [
      ListView.builder(
          itemCount: 20,
          shrinkWrap: true,
          physics: NeverScrollableScrollPhysics(),
          itemBuilder: (ctx, index) {
            return Padding(
              padding: const EdgeInsets.all(8.0),
              child: Card(
                child: Text('Test item $index'),
              ),
            );
          }),
      SizedBox(
        height: 250,
        child: GoogleMap(
          mapType: MapType.hybrid,
          initialCameraPosition: _kGooglePlex,
          onMapCreated: (GoogleMapController controller) {
            _controller.complete(controller);
          },
        ),
      ),
      ListView.builder(
          itemCount: 50,
          shrinkWrap: true,
          physics: NeverScrollableScrollPhysics(),
          itemBuilder: (ctx, index) {
            return Padding(
              padding: const EdgeInsets.all(8.0),
              child: Card(
                child: Text('Test item $index'),
              ),
            );
          }),
    ]
),

); }

于 2021-07-06T03:24:07.793 回答