rorystephenson / flutter_map_marker_popup

Popups for flutter_map markers
BSD 3-Clause "New" or "Revised" License
103 stars 84 forks source link

Error thrown by stack as PopupMarkerLayerOptions is null #7

Closed Dereumaux-Adrien closed 4 years ago

Dereumaux-Adrien commented 4 years ago

Both examples run smoothly in my flutter_map_marker_popup clone.

But when I try a simpler version in my own project, I get the following stack:

Launching lib\simple_map_with_popup.dart on ASUS I01WD in debug mode...
Running Gradle task 'assembleDebug'...
√ Built build\app\outputs\apk\debug\app-debug.apk.
Installing build\app\outputs\apk\app.apk...
D/FlutterActivity(12790): Using the launch theme as normal theme.
D/FlutterActivityAndFragmentDelegate(12790): Setting up FlutterEngine.
D/FlutterActivityAndFragmentDelegate(12790): No preferred FlutterEngine was provided. Creating a new FlutterEngine for this FlutterFragment.
D/FlutterActivityAndFragmentDelegate(12790): Attaching FlutterEngine to the Activity that owns this Fragment.
D/FlutterView(12790): Attaching to a FlutterEngine: io.flutter.embedding.engine.FlutterEngine@e6a89bb
D/FlutterActivityAndFragmentDelegate(12790): Executing Dart entrypoint: main, and sending initial route: /
Debug service listening on ws://127.0.0.1:54518/2H6JV7ZKrb8=/ws
Syncing files to device ASUS I01WD...
I/flutter (12790): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (12790): The following assertion was thrown building LayoutBuilder:
I/flutter (12790): Stack's children must not contain any null values, but a null value was found at index 1
I/flutter (12790): 
I/flutter (12790): The relevant error-causing widget was:
I/flutter (12790):   LayoutBuilder
I/flutter (12790):   file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_map-0.9.0/lib/src/map/flutter_map_state.dart:73:12
I/flutter (12790): 
I/flutter (12790): When the exception was thrown, this was the stack:
I/flutter (12790): #0      new MultiChildRenderObjectWidget.<anonymous closure> (package:flutter/src/widgets/framework.dart:1701:11)
I/flutter (12790): #1      new MultiChildRenderObjectWidget (package:flutter/src/widgets/framework.dart:1707:8)
I/flutter (12790): #2      new Stack (package:flutter/src/widgets/basic.dart:3194:8)
I/flutter (12790): #3      FlutterMapState.build.<anonymous closure> (package:flutter_map/src/map/flutter_map_state.dart:97:24)
I/flutter (12790): #4      _LayoutBuilderElement._layout.<anonymous closure> (package:flutter/src/widgets/layout_builder.dart)
I/flutter (12790): #5      BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2412:19)
I/flutter (12790): #6      _LayoutBuilderElement._layout (package:flutter/src/widgets/layout_builder.dart:95:11)
I/flutter (12790): #7      RenderObject.invokeLayoutCallback.<anonymous closure> (package:flutter/src/rendering/object.dart:1823:58)
I/flutter (12790): #8      PipelineOwner._enableMutationsToDirtySubtrees (package:flutter/src/rendering/object.dart:875:15)
I/flutter (12790): #9      RenderObject.invokeLayoutCallback (package:flutter/src/rendering/object.dart:1823:13)
I/flutter (12790): #10     RenderConstrainedLayoutBuilder.layoutAndBuildChild (package:flutter/src/widgets/layout_builder.dart:173:5)
I/flutter (12790): #11     _RenderLayoutBuilder.performLayout (package:flutter/src/widgets/layout_builder.dart:240:5)
I/flutter (12790): #12     RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter (12790): #13     RenderStack.performLayout (package:flutter/src/rendering/stack.dart:505:15)
I/flutter (12790): #14     RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter (12790): #15     MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:163:11)
I/flutter (12790): #16     _ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:477:7)
I/flutter (12790): #17     MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:232:7)
I/flutter (12790): #18     RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:391:14)
I/flutter (12790): #19     RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter (12790): #20     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (12790): #21     RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter (12790): #22     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (12790): #23     _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1232:11)
I/flutter (12790): #24     RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter (12790): #25     MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:163:11)
I/flutter (12790): #26     _ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:477:7)
I/flutter (12790): #27     MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:232:7)
I/flutter (12790): #28     RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:391:14)
I/flutter (12790): #29     RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter (12790): #30     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (12790): #31     RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter (12790): #32     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (12790): #33     _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1232:11)
I/flutter (12790): #34     RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter (12790): #35     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (12790): #36     RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter (12790): #37     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (12790): #38     RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter (12790): #39     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (12790): #40     RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter (12790): #41     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (12790): #42     RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter (12790): #43     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (12790): #44     RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter (12790): #45     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (12790): #46     RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter (12790): #47     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (12790): #48     RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter (12790): #49     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (12790): #50     RenderOffstage.performLayout (package:flutter/src/rendering/proxy_box.dart:3168:13)
I/flutter (12790): #51     RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter (12790): #52     RenderStack.performLayout (package:flutter/src/rendering/stack.dart:505:15)
I/flutter (12790): #53     RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter (12790): #54     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (12790): #55     RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter (12790): #56     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (12790): #57     RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter (12790): #58     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (12790): #59     RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter (12790): #60     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (12790): #61     RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter (12790): #62     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (12790): #63     RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter (12790): #64     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (12790): #65     RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter (12790): #66     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (12790): #67     RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
I/flutter (12790): #68     RenderView.performLayout (package:flutter/src/rendering/view.dart:167:13)
I/flutter (12790): #69     RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1584:7)
I/flutter (12790): #70     PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:844:18)
I/flutter (12790): #71     RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:344:19)
I/flutter (12790): #72     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:774:13)
I/flutter (12790): #73     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:283:5)
I/flutter (12790): #74     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1102:15)
I/flutter (12790): #75     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1041:9)
I/flutter (12790): #76     SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:850:7)
I/flutter (12790): #85     _Timer._runTimers (dart:isolate-patch/timer_impl.dart:384:19)
I/flutter (12790): #86     _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:418:5)
I/flutter (12790): #87     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12)
I/flutter (12790): (elided 8 frames from package dart:async and package dart:async-patch)
I/flutter (12790): 
I/flutter (12790): ════════════════════════════════════════════════════════════════════════════════════════════════════
E/AccessibilityBridge(12790): VirtualView node must not be the root node.

Here you can find my dart code:

import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_marker_popup/flutter_map_marker_popup.dart';
import 'package:latlong/latlong.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Welcome to Flutter',
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Test'),
        ),
        body: AnimatedMapPage(),
      ),
    );
  }
}

class AnimatedMapPage extends StatefulWidget {
  @override
  AnimatedMapPageState createState() {
    return AnimatedMapPageState();
  }
}

class AnimatedMapPageState extends State<AnimatedMapPage>
    with TickerProviderStateMixin {
  MapController mapController;
  PopupController popupLayerController = PopupController();

  @override
  Widget build(BuildContext context) {
    void _onTap(LatLng point) =>
        {
          popupLayerController.hidePopup()
        };

    final _markers = <Marker>[
      Marker(
          point: LatLng(1, 1),
          builder: (BuildContext c) =>
              Icon(Icons.edit_location,
                  color: Colors.blueAccent, size: 30)),
      Marker(
          point: LatLng(2, 2),
          builder: (BuildContext c) =>
              Icon(Icons.edit_location,
                  color: Colors.blueAccent, size: 30)),
    ];

    return Scaffold(
      body: Stack(
        children: <Widget>[
          FlutterMap(
            mapController: mapController,
            options: MapOptions(
                center: LatLng(51.5, -0.09),
                zoom: 5.0,
                maxZoom: 19.0,
                minZoom: 2.0,
                onTap: _onTap),
            layers: <LayerOptions>[
              TileLayerOptions(
                  urlTemplate:
                  'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
                  subdomains: ['a', 'b', 'c']),
//              MarkerLayerOptions(markers: _markers),
              PopupMarkerLayerOptions(
                markers: _markers,
                popupController: popupLayerController,
                popupBuilder: (_, Marker marker) {
                  return Card(child: const Text('Not a monument'));
                },
              ),
            ],
          ),
        ],
      ),
    );
  }
}

If I use the simple MarkerLayerOptions instead of the PopupMarkerLayerOptions, everything runs smoothly.

My pubspec.yaml:

version: 1.0.0+1

environment:
  sdk: ">=2.2.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  # Added by me
  cloud_firestore: ^0.13.6
  fluttertoast: ^3.1.3
  flutter_bloc: ^4.0.0
  flutter_map: any
  geoflutterfire: any
  geolocator: ^5.3.0
  latlong: ^0.6.1
  pedantic: ^1.8.0
  flutter_map_marker_popup: 0.1.4
rorystephenson commented 4 years ago

Hi @Dereumaux-Adrien !

Looks like you're missing the plugin declaration in the MapOptions, this:

options: MapOptions(
                center: LatLng(51.5, -0.09),
                zoom: 5.0,
                maxZoom: 19.0,
                minZoom: 2.0,
                onTap: _onTap),

should be:

options: MapOptions(
                center: LatLng(51.5, -0.09),
                zoom: 5.0,
                maxZoom: 19.0,
                minZoom: 2.0,
                onTap: _onTap,
                plugins: [PopupMarkerPlugin()],
        ),

Let me know how that goes.

Dereumaux-Adrien commented 4 years ago

Indeed, that was exactly this.

Works perfectly now, thank you