Skip to content

Map not loading properly in a List View #623

@RobinCPel

Description

@RobinCPel

Hi!

I am having some issues when trying to display multiple maps in a list view, demo:
flutter_map_test

The app is supposed to show ten maps in a column, but the ones that are off screen are not loaded properly once they do move on screen.

Source code of the demo:

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('🗺'), centerTitle: true),
      body: Center(
        child: ListView.builder(
          itemBuilder: (context, i) {
            if (i.isOdd) return Divider(height: 16.0);
            final index = i ~/ 2;
            if (index >= 10) return null;
            return _mapWidget();
          },
        ),
      ),
    );
  }

  Widget _mapWidget() {
    return Container(
      height: 150,
      child: FlutterMap(
        options: MapOptions(
          center: LatLng(51.993693, 6.718940),
          zoom: 12.0,
        ),
        layers: [
          TileLayerOptions(
            urlTemplate: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
            subdomains: ['a', 'b', 'c'],
          ),
        ],
      ),
    );
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions