【问题标题】:Using Google Maps with PageView将 Google 地图与 PageView 结合使用
【发布时间】:2023-01-25 06:11:22
【问题描述】:

我正在尝试将地图呈现为 PageView 中的第一页/幻灯片,效果非常好,我什至可以滚动/滑动到第二页,但是当我尝试返回地图时,我收到一条错误消息,说明未来已经执行

PageView(
            controller: pageController,
            children: [
              GoogleMap(
                buildingsEnabled: false,
                myLocationEnabled: true,
                scrollGesturesEnabled: false,
                myLocationButtonEnabled: false,
                mapType: MapType.normal,
                initialCameraPosition: CameraPosition(
                  target: LatLng(widget.task.locationCoords.latitude,
                      widget.task.locationCoords.longitude),
                  zoom: 15,
                ),
                onMapCreated: (GoogleMapController controller) {
                  _controller.complete(controller);
                },
                // markers: {
                //   Marker(
                //     // icon: customIcon,
                //     markerId: MarkerId(widget.task.id),
                //     position: LatLng(widget.task.locationCoords.latitude,
                //         widget.task.locationCoords.longitude),
                //     infoWindow: InfoWindow(
                //       title: widget.task.title,
                //       snippet: widget.task.title,
                //     ),
                //   )
                // },
                circles: {
                  Circle(
                      circleId: const CircleId('taskArea'),
                      center: LatLng(widget.task.locationCoords.latitude,
                          widget.task.locationCoords.longitude),
                      radius: 250,
                      fillColor: Colors.blue.shade100,
                      strokeColor: Colors.blue.shade100),
                },
              ),
              Image.network(
                  'https://www.saturdayeveningpost.com/wp-content/uploads/satevepost/mowing_sl.jpg',
                  fit: BoxFit.cover)
            ],
            onPageChanged: (page) {
              setState(() {
                currentPage = page + 1;
              });
            },
            scrollDirection: Axis.horizontal,
          )),

【问题讨论】:

    标签: flutter google-maps future flutter-pageview


    【解决方案1】:

    您应该将地图放在 StatefulWidget 中并使用 AutomaticKeepAliveClientMixin see here

    【讨论】:

      猜你喜欢
      • 2019-05-27
      • 2021-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多