簡體   English   中英

谷歌地圖 + CustomPaint Flutter

[英]Google Maps + CustomPaint Flutter

將 CustomPaint 小部件置於 Google 地圖小部件之上時,地圖不再接收觸摸事件(滾動、平移、點擊等)。

是否可以在保持地圖交互的同時將 CustomPaint 小部件放在地圖上方? 這是一個解釋案例的示例代碼:

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

void main() =>
    runApp(
        MaterialApp(
          title: 'Flutter Google Maps Demo',
          home: Scaffold(
            body: Scaffold(
              body: Stack(children: <Widget>[
                GoogleMap(
                  initialCameraPosition: CameraPosition(
                    target: LatLng(37.42796133580664, -122.085749655962),
                    zoom: 14.4746,
                  ),
                ),
                CustomPaint(
                  painter: ShapesPainter(),
                  child: Container(height: 500),
                )
              ],)

            ),
          ),
        )
    );

class ShapesPainter extends CustomPainter {
  @override
  void paint(Canvas canvas, Size size) {
    final paint = Paint();
    paint.color = Color(0xFF3f6cbf);
    canvas.drawCircle(Offset(0, 0), 300, paint);
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) => false;
}

IgnorePointer包裹CustomPainter小部件,它將忽略任何點擊或其他手勢閱讀更多

最終代碼

Stack(
  children: <Widget>[
    GoogleMap(
      initialCameraPosition: CameraPosition(
        target: LatLng(37.42796133580664, -122.085749655962),
        zoom: 14.4746,
      ),
    ),
    IgnorePointer(
      child: CustomPaint(
        painter: ShapesPainter(),
        child: Container(height: 500),
      ),
    )
  ],
)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM