From efd31f63f4675da20ef4a8dc4e708c0d7b455fb1 Mon Sep 17 00:00:00 2001 From: Jan Boon Date: Fri, 11 May 2018 08:04:02 +0800 Subject: [PATCH] Allow custom placeholder image and use transparent_image for default --- flutter_map/lib/src/layer/tile_layer.dart | 9 ++++++--- flutter_map/pubspec.yaml | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/flutter_map/lib/src/layer/tile_layer.dart b/flutter_map/lib/src/layer/tile_layer.dart index 55ccc798e..7b4790c08 100644 --- a/flutter_map/lib/src/layer/tile_layer.dart +++ b/flutter_map/lib/src/layer/tile_layer.dart @@ -3,6 +3,7 @@ import 'dart:typed_data'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:latlong/latlong.dart'; +import 'package:transparent_image/transparent_image.dart'; import 'package:flutter_map/src/core/bounds.dart'; import 'package:flutter_map/src/core/point.dart'; import 'package:flutter_map/src/map/map.dart'; @@ -19,6 +20,7 @@ class TileLayerOptions extends LayerOptions { final double zoomOffset; final List subdomains; final Color backgroundColor; + ImageProvider placeholderImage; Map additionalOptions; TileLayerOptions({ @@ -30,6 +32,7 @@ class TileLayerOptions extends LayerOptions { this.additionalOptions = const {}, this.subdomains = const [], this.backgroundColor = Colors.grey[300], + this.placeholderImage, }); } @@ -324,7 +327,6 @@ class _TileLayerState extends State { var pos = (tilePos).multiplyBy(level.scale) + level.translatePoint; var width = tileSize.x * level.scale; var height = tileSize.y * level.scale; - var blankImageBytes = new Uint8List(0); return new Positioned( left: pos.x.toDouble(), @@ -335,8 +337,9 @@ class _TileLayerState extends State { child: new FadeInImage( fadeInDuration: const Duration(milliseconds: 100), key: new Key(_tileCoordsToKey(coords)), - // here `bytes` is a Uint8List containing the bytes for the in-memory image - placeholder: new MemoryImage(blankImageBytes), + placeholder: options.placeholderImage != null + ? options.placeholderImage + : new MemoryImage(kTransparentImage), image: new NetworkImage(getTileUrl(coords)), fit: BoxFit.fill, ), diff --git a/flutter_map/pubspec.yaml b/flutter_map/pubspec.yaml index a6940d974..2a4810a8e 100644 --- a/flutter_map/pubspec.yaml +++ b/flutter_map/pubspec.yaml @@ -14,3 +14,4 @@ dependencies: latlong: ^0.4.0 tuple: ^1.0.0 quiver: ^0.28.0 + transparent_image: ^0.1.0