Skip to content

Tile builder not invoked on load error #2154

@jholsten

Description

@jholsten

What is the bug?

The tileBuilder function of a tile layer is only invoked on an image error if an errorImage has been passed. Therefore, it is not possible to construct a custom error widget in the tile builder itself.

How can we reproduce it?

Create a tile layer with a URL template which produces an error, e.g. https://example.com/{z}/{y}/{x}.

    FlutterMap(
      children: [
        TileLayer(
          urlTemplate: 'https://example.com/{z}/{y}/{x}',
          tileBuilder: (context, tileWidget, tile) {
            if (tile.loadError) { // This is never true
              return Icon(Icons.cancel);
            }
            return tileWidget;
          },
        ),
      ],
    );

Note that the builder never returns the icon since loadError is always false.

Do you have a potential solution?

In TileImage._onImageLoadError, notifyListeners() is only invoked in _display(), which in turn is only called if errorImage != null. To trigger a rebuild even if errorImage is not set, listeners should be notified in that case as well.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions