admin管理员组

文章数量:1388835

What is the bug?

Hello.

I'm using flutter_map: ^8.1.1 like follow:

return StreamBuilder<
                                                                List<Marker>>(
                                                            stream:
                                                                carMarkerStream,
                                                            builder: (context,
                                                                snapshot) {
                                                              return fm
                                                                  .FlutterMap(
                                                                mapController:
                                                                    _fmController,
                                                                options: fm
                                                                    .MapOptions(
                                                                        onMapEvent:
                                                                            (v) async {
                                                                          if (v.source == fm.MapEventSource.nonRotatedSizeChange &&
                                                                              addressList.isEmpty) {
                                                                            _centerLocation =
                                                                                LatLng(v.camera.center.latitude, v.camera.center.longitude);
                                                                            setState(() {});

                                                                            var val =
                                                                                await geoCoding(_centerLocation.latitude, _centerLocation.longitude);
                                                                            if (val !=
                                                                                '') {
                                                                              setState(() {
                                                                                if (addressList.where((element) => element.type == 'pickup').isNotEmpty) {
                                                                                  var add = addressList.firstWhere((element) => element.type == 'pickup');
                                                                                  add.address = val;
                                                                                  add.latlng = LatLng(_centerLocation.latitude, _centerLocation.longitude);
                                                                                } else {
                                                                                  addressList.add(AddressList(id: '1', type: 'pickup', address: val, pickup: true, latlng: LatLng(_centerLocation.latitude, _centerLocation.longitude), name: userDetails['name'], number: userDetails['mobile']));
                                                                                }
                                                                              });

                                                                              _lastCenter = _centerLocation;
                                                                              ischanged = false;
                                                                            }
                                                                          }
                                                                          if (v.source ==
                                                                              fm.MapEventSource.dragEnd) {
                                                                            _centerLocation =
                                                                                LatLng(v.camera.center.latitude, v.camera.center.longitude);
                                                                            setState(() {});
                                                                            if (userDetails['enable_map_location_icon_drag_and_drop_feature'] ==
                                                                                '0') {
                                                                              var val = await geoCoding(_centerLocation.latitude, _centerLocation.longitude);
                                                                              lowerLat = _centerLocation.latitude - (lat * 1.24);
                                                                              lowerLon = _centerLocation.longitude - (lon * 1.24);
                                                                              greaterLat = _centerLocation.latitude + (lat * 1.24);
                                                                              greaterLon = _centerLocation.longitude + (lon * 1.24);
                                                                              lower = geo.encode(lowerLon, lowerLat);
                                                                              higher = geo.encode(greaterLon, greaterLat);

                                                                              fdb = FirebaseDatabase.instance.ref('drivers').orderByChild('g').startAt(lower).endAt(higher);
                                                                              if (val != '') {
                                                                                setState(() {
                                                                                  if (addressList.where((element) => element.type == 'pickup').isNotEmpty) {
                                                                                    var add = addressList.firstWhere((element) => element.type == 'pickup');
                                                                                    add.address = val;
                                                                                    add.latlng = LatLng(_centerLocation.latitude, _centerLocation.longitude);
                                                                                  } else {
                                                                                    addressList.add(AddressList(id: '1', type: 'pickup', address: val, pickup: true, latlng: LatLng(_centerLocation.latitude, _centerLocation.longitude), name: userDetails['name'], number: userDetails['mobile']));
                                                                                  }
                                                                                });

                                                                                _lastCenter = _centerLocation;
                                                                                ischanged = false;
                                                                              }
                                                                            }
                                                                          }
                                                                        },
                                                                        onPositionChanged: (p,
                                                                            l) async {
                                                                          if (l ==
                                                                              false) {
                                                                            if (addressList.isEmpty) {
                                                                              _centerLocation = LatLng(p.center.latitude, p.center.longitude);
                                                                              setState(() {});

                                                                              var val = await geoCoding(_centerLocation.latitude, _centerLocation.longitude);
                                                                              lowerLat = _centerLocation.latitude - (lat * 1.24);
                                                                              if (val != '') {
                                                                                setState(() {
                                                                                  if (addressList.where((element) => element.type == 'pickup').isNotEmpty) {
                                                                                    var add = addressList.firstWhere((element) => element.type == 'pickup');
                                                                                    add.address = val;
                                                                                    add.latlng = LatLng(_centerLocation.latitude, _centerLocation.longitude);
                                                                                  } else {
                                                                                    addressList.add(AddressList(id: '1', type: 'pickup', address: val, pickup: true, latlng: LatLng(_centerLocation.latitude, _centerLocation.longitude), name: userDetails['name'], number: userDetails['mobile']));
                                                                                  }
                                                                                });

                                                                                _lastCenter = _centerLocation;
                                                                                ischanged = false;
                                                                              }
                                                                            }
                                                                          }
                                                                        },
                                                                        // interactiveFlags: ~fm
                                                                        //     .InteractiveFlag
                                                                        //     .doubleTapZoom,
                                                                        initialCenter: fmlt.LatLng(
                                                                            center
                                                                                .latitude,
                                                                            center
                                                                                .longitude),
                                                                        initialZoom:
                                                                            16,
                                                                        onTap: (P,
                                                                            L) {}),
                                                                children: [
                                                                  fm.TileLayer(
                                                                    // minZoom: 10,
                                                                    urlTemplate: (isDarkTheme ==
                                                                            false)
                                                                        ? '/{z}/{x}/{y}.png'
                                                                        : 'https://{s}.basemaps.cartocdn/dark_all/{z}/{x}/{y}.png',
                                                                    // subdomains: ['a', 'b', 'c', 'd'],
                                                                    userAgentPackageName:
                                                                        'com.example.app',
                                                                  ),
                                                                  fm.MarkerLayer(
                                                                    markers: myMarkers
                                                                        .asMap()
                                                                        .map(
                                                                          (k, value) =>
                                                                              MapEntry(
                                                                            k,
                                                                            fm.Marker(
                                                                              alignment: Alignment.topCenter,
                                                                              point: fmlt.LatLng(myMarkers[k].position.latitude, myMarkers[k].position.longitude),
                                                                              width: media.width * 0.7,
                                                                              height: 50,
                                                                              child: RotationTransition(
                                                                                turns: AlwaysStoppedAnimation(myMarkers[k].rotation / 360),
                                                                                child: Image.asset(
                                                                                  (myMarkers[k].markerId.toString().replaceAll('MarkerId(', '').replaceAll(')', '').split('#')[2].toString() == 'taxi')
                                                                                      ? 'assets/images/top-taxi.png'
                                                                                      : (myMarkers[k].markerId.toString().replaceAll('MarkerId(', '').replaceAll(')', '').split('#')[2].toString() == 'truck')
                                                                                          ? 'assets/images/dev.png'
                                                                                          : 'assets/images/bicy.png',
                                                                                ),
                                                                              ),
                                                                            ),
                                                                          ),
                                                                        )
                                                                        .values
                                                                        .toList(),
                                                                  ),
                                                                  const fm
                                                                      .RichAttributionWidget(
                                                                    attributions: [],
                                                                  ), 
                                                                ],
                                                              );
                                                            });

But, as you can see on the Screen Shot below, it is hidden. I try anything I know but it does display at all:

I want to point out that sometimes the map displays very well but other times it hides.

Please, I really need your help.

Do you have a potential solution?

What is the bug?

Hello.

I'm using flutter_map: ^8.1.1 like follow:

return StreamBuilder<
                                                                List<Marker>>(
                                                            stream:
                                                                carMarkerStream,
                                                            builder: (context,
                                                                snapshot) {
                                                              return fm
                                                                  .FlutterMap(
                                                                mapController:
                                                                    _fmController,
                                                                options: fm
                                                                    .MapOptions(
                                                                        onMapEvent:
                                                                            (v) async {
                                                                          if (v.source == fm.MapEventSource.nonRotatedSizeChange &&
                                                                              addressList.isEmpty) {
                                                                            _centerLocation =
                                                                                LatLng(v.camera.center.latitude, v.camera.center.longitude);
                                                                            setState(() {});

                                                                            var val =
                                                                                await geoCoding(_centerLocation.latitude, _centerLocation.longitude);
                                                                            if (val !=
                                                                                '') {
                                                                              setState(() {
                                                                                if (addressList.where((element) => element.type == 'pickup').isNotEmpty) {
                                                                                  var add = addressList.firstWhere((element) => element.type == 'pickup');
                                                                                  add.address = val;
                                                                                  add.latlng = LatLng(_centerLocation.latitude, _centerLocation.longitude);
                                                                                } else {
                                                                                  addressList.add(AddressList(id: '1', type: 'pickup', address: val, pickup: true, latlng: LatLng(_centerLocation.latitude, _centerLocation.longitude), name: userDetails['name'], number: userDetails['mobile']));
                                                                                }
                                                                              });

                                                                              _lastCenter = _centerLocation;
                                                                              ischanged = false;
                                                                            }
                                                                          }
                                                                          if (v.source ==
                                                                              fm.MapEventSource.dragEnd) {
                                                                            _centerLocation =
                                                                                LatLng(v.camera.center.latitude, v.camera.center.longitude);
                                                                            setState(() {});
                                                                            if (userDetails['enable_map_location_icon_drag_and_drop_feature'] ==
                                                                                '0') {
                                                                              var val = await geoCoding(_centerLocation.latitude, _centerLocation.longitude);
                                                                              lowerLat = _centerLocation.latitude - (lat * 1.24);
                                                                              lowerLon = _centerLocation.longitude - (lon * 1.24);
                                                                              greaterLat = _centerLocation.latitude + (lat * 1.24);
                                                                              greaterLon = _centerLocation.longitude + (lon * 1.24);
                                                                              lower = geo.encode(lowerLon, lowerLat);
                                                                              higher = geo.encode(greaterLon, greaterLat);

                                                                              fdb = FirebaseDatabase.instance.ref('drivers').orderByChild('g').startAt(lower).endAt(higher);
                                                                              if (val != '') {
                                                                                setState(() {
                                                                                  if (addressList.where((element) => element.type == 'pickup').isNotEmpty) {
                                                                                    var add = addressList.firstWhere((element) => element.type == 'pickup');
                                                                                    add.address = val;
                                                                                    add.latlng = LatLng(_centerLocation.latitude, _centerLocation.longitude);
                                                                                  } else {
                                                                                    addressList.add(AddressList(id: '1', type: 'pickup', address: val, pickup: true, latlng: LatLng(_centerLocation.latitude, _centerLocation.longitude), name: userDetails['name'], number: userDetails['mobile']));
                                                                                  }
                                                                                });

                                                                                _lastCenter = _centerLocation;
                                                                                ischanged = false;
                                                                              }
                                                                            }
                                                                          }
                                                                        },
                                                                        onPositionChanged: (p,
                                                                            l) async {
                                                                          if (l ==
                                                                              false) {
                                                                            if (addressList.isEmpty) {
                                                                              _centerLocation = LatLng(p.center.latitude, p.center.longitude);
                                                                              setState(() {});

                                                                              var val = await geoCoding(_centerLocation.latitude, _centerLocation.longitude);
                                                                              lowerLat = _centerLocation.latitude - (lat * 1.24);
                                                                              if (val != '') {
                                                                                setState(() {
                                                                                  if (addressList.where((element) => element.type == 'pickup').isNotEmpty) {
                                                                                    var add = addressList.firstWhere((element) => element.type == 'pickup');
                                                                                    add.address = val;
                                                                                    add.latlng = LatLng(_centerLocation.latitude, _centerLocation.longitude);
                                                                                  } else {
                                                                                    addressList.add(AddressList(id: '1', type: 'pickup', address: val, pickup: true, latlng: LatLng(_centerLocation.latitude, _centerLocation.longitude), name: userDetails['name'], number: userDetails['mobile']));
                                                                                  }
                                                                                });

                                                                                _lastCenter = _centerLocation;
                                                                                ischanged = false;
                                                                              }
                                                                            }
                                                                          }
                                                                        },
                                                                        // interactiveFlags: ~fm
                                                                        //     .InteractiveFlag
                                                                        //     .doubleTapZoom,
                                                                        initialCenter: fmlt.LatLng(
                                                                            center
                                                                                .latitude,
                                                                            center
                                                                                .longitude),
                                                                        initialZoom:
                                                                            16,
                                                                        onTap: (P,
                                                                            L) {}),
                                                                children: [
                                                                  fm.TileLayer(
                                                                    // minZoom: 10,
                                                                    urlTemplate: (isDarkTheme ==
                                                                            false)
                                                                        ? 'https://tile.openstreetmap./{z}/{x}/{y}.png'
                                                                        : 'https://{s}.basemaps.cartocdn/dark_all/{z}/{x}/{y}.png',
                                                                    // subdomains: ['a', 'b', 'c', 'd'],
                                                                    userAgentPackageName:
                                                                        'com.example.app',
                                                                  ),
                                                                  fm.MarkerLayer(
                                                                    markers: myMarkers
                                                                        .asMap()
                                                                        .map(
                                                                          (k, value) =>
                                                                              MapEntry(
                                                                            k,
                                                                            fm.Marker(
                                                                              alignment: Alignment.topCenter,
                                                                              point: fmlt.LatLng(myMarkers[k].position.latitude, myMarkers[k].position.longitude),
                                                                              width: media.width * 0.7,
                                                                              height: 50,
                                                                              child: RotationTransition(
                                                                                turns: AlwaysStoppedAnimation(myMarkers[k].rotation / 360),
                                                                                child: Image.asset(
                                                                                  (myMarkers[k].markerId.toString().replaceAll('MarkerId(', '').replaceAll(')', '').split('#')[2].toString() == 'taxi')
                                                                                      ? 'assets/images/top-taxi.png'
                                                                                      : (myMarkers[k].markerId.toString().replaceAll('MarkerId(', '').replaceAll(')', '').split('#')[2].toString() == 'truck')
                                                                                          ? 'assets/images/dev.png'
                                                                                          : 'assets/images/bicy.png',
                                                                                ),
                                                                              ),
                                                                            ),
                                                                          ),
                                                                        )
                                                                        .values
                                                                        .toList(),
                                                                  ),
                                                                  const fm
                                                                      .RichAttributionWidget(
                                                                    attributions: [],
                                                                  ), 
                                                                ],
                                                              );
                                                            });

But, as you can see on the Screen Shot below, it is hidden. I try anything I know but it does display at all:

I want to point out that sometimes the map displays very well but other times it hides.

Please, I really need your help.

Do you have a potential solution?

Share Improve this question asked Mar 15 at 10:24 Marc-aurèle ChégnimonhanMarc-aurèle Chégnimonhan 175 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

From what I see, the snapshot from your StreamBuilder is not in use, you might as well remove the StreamBuilder.

Anytime you setState, your StreamBuilder rebuilds which might cause all the functions in there to get called multiple times and cause an infinite loop.

本文标签: flutterquotfluttermapquot does not show map everytimes (map hides sometimes)Stack Overflow