Google Maps + CustomPaint Flutter

时间:2019-03-10 08:19:02

标签: android flutter

将CustomPaint小部件放置在Google Maps小部件顶部时,地图不再接收触摸事件(滚动,平移,点击,.. etc等)。

是否可以将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;
}

0 个答案:

没有答案