ibrierley / flutter_map_line_editor

A basic line/poly editor that works with flutter_map and dragmarkers.
MIT License
46 stars 27 forks source link

Drag marker does not update polygon points #43

Open V3ntus opened 8 months ago

V3ntus commented 8 months ago
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_line_editor/flutter_map_line_editor.dart';

class _KmzMapState extends State<KmzMap> {
  PolyEditor? polyEditor;
  List<LatLng>? polygonToEdit;

  @override
  Widget build(BuildContext context) {
    return FlutterMap(
      children: [
        TileLayer(...),

        // GestureDetector + PolygonLayer that instantiates polyEditor onTap of existing polygon:
        // polyEditor = PolyEditor(points: polygonToEdit!, callbackRefresh: () => setState(() {}))

        PolygonLayer(
          polygons: [Polygon(
            color: Colors.purple,
            points: polygonToEdit!,
          )],
        ),
        // ...
        DragMarkers(markers: polyEditor!.edit()),
        // ... DragMarkers is the last layer, there is only a RichAttributionLayer after it
      ]
    );
  }
}

In the screenshot, the drag marker can be interacted with, but it does not rebuild the PolygonLayer. No console output either, but callbackRefresh does get called. image

Versions:
flutter_map: git+95ff0191981b87b24430ef434d7806e5a3017a50 flutter_map_dragmarker: 6.0.0 flutter_map_line_editor: 6.0.0

I am using bleeding-edge flutter_map as I require hit testing for the polygons. My app's map will be projecting multiple polygons that will be available to the user to edit and interact with as they please.

V3ntus commented 8 months ago

Looks like it could be slightly related to #42, I'll try to pull latest master and test with that Pulled latest master of this repo, no changes. Even refactored my code to look more like the example (instantiate the Polygon during widget instantiation, but dynamically clear/add the points when the user selects another polygon), no change. I'll look into exploring other state management solutions and have the PolygonLayer for "testPolygon" wrapped in a Consumer

V3ntus commented 8 months ago

I believe the issue is caused by Flutter (or at least my implementation) not detecting changes due to this library using list mutation: https://github.com/ibrierley/flutter_map_line_editor/blob/753e3268d4622ae19b0d2af6d5c40a49b13512b3/lib/src/poly_editor.dart#L28 https://github.com/ibrierley/flutter_map_line_editor/blob/753e3268d4622ae19b0d2af6d5c40a49b13512b3/lib/src/poly_editor.dart#L40

I was able to get my desired behavior by reassigning points after each marker operation:

points = List.from(points);