Skip to content

Commit

Permalink
Merge branch 'fix-tilelayer-dipose' of https://github.com/kuhnroyal/f…
Browse files Browse the repository at this point in the history
…lutter_map into kuhnroyal-fix-tilelayer-dipose
  • Loading branch information
johnpryan committed Jul 8, 2020
2 parents 37fbca0 + 289e4be commit 9d64fac
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ ios/.generated/
pubspec.lock
.flutter-plugins
.vscode/
.idea
*.iml
GeneratedPluginRegistrant.h
GeneratedPluginRegistrant.m
GeneratedPluginRegistrant.java
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [UNRELEASED]
- Fix TileLayer/Tiles not getting disposed correctly (#595)

## [0.9.0] - 4/6/2020
- Improve tile management (#572) - This is a huge improvement aligns
tile rendering with Leaflet's behavior.
Expand Down
36 changes: 19 additions & 17 deletions example/lib/pages/live_location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class LiveLocationPage extends StatefulWidget {
}

class _LiveLocationPageState extends State<LiveLocationPage> {

LocationData _currentLocation;
MapController _mapController;

Expand Down Expand Up @@ -50,27 +49,27 @@ class _LiveLocationPageState extends State<LiveLocationPage> {
if (_permission) {
location = await _locationService.getLocation();
_currentLocation = location;
_locationService.onLocationChanged().listen((LocationData result) async {
_locationService
.onLocationChanged()
.listen((LocationData result) async {
if (mounted) {
setState(() {
_currentLocation = result;

// If Live Update is enabled, move map center
if (_liveUpdate) {
_mapController.move(
LatLng(
_currentLocation.latitude,
LatLng(_currentLocation.latitude,
_currentLocation.longitude),
_mapController.zoom
);
_mapController.zoom);
}
});
}
});
}
} else {
serviceRequestResult = await _locationService.requestService();
if(serviceRequestResult){
if (serviceRequestResult) {
initLocationService();
return;
}
Expand All @@ -93,7 +92,8 @@ class _LiveLocationPageState extends State<LiveLocationPage> {
// Until currentLocation is initially updated, Widget can locate to 0, 0
// by default or store previous location value to show.
if (_currentLocation != null) {
currentLatLng = LatLng(_currentLocation.latitude, _currentLocation.longitude);
currentLatLng =
LatLng(_currentLocation.latitude, _currentLocation.longitude);
} else {
currentLatLng = LatLng(0, 0);
}
Expand Down Expand Up @@ -121,23 +121,25 @@ class _LiveLocationPageState extends State<LiveLocationPage> {
children: [
Padding(
padding: EdgeInsets.only(top: 8.0, bottom: 8.0),
child: _serviceError.isEmpty ?
Text('This is a map that is showing '
'(${currentLatLng.latitude}, ${currentLatLng.longitude}).') :
Text('Error occured while acquiring location. Error Message : '
'$_serviceError'),
child: _serviceError.isEmpty
? Text('This is a map that is showing '
'(${currentLatLng.latitude}, ${currentLatLng.longitude}).')
: Text(
'Error occured while acquiring location. Error Message : '
'$_serviceError'),
),
Flexible(
child: FlutterMap(
mapController: _mapController,
options: MapOptions(
center: LatLng(currentLatLng.latitude, currentLatLng.longitude),
center:
LatLng(currentLatLng.latitude, currentLatLng.longitude),
zoom: 5.0,
),
layers: [
TileLayerOptions(
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c'],
// For example purposes. It is recommended to use
// TileProvider with a caching and retry strategy, like
Expand All @@ -152,8 +154,8 @@ class _LiveLocationPageState extends State<LiveLocationPage> {
),
),
floatingActionButton: FloatingActionButton(
onPressed: () => _liveUpdate = !_liveUpdate,
child: _liveUpdate ? Icon(Icons.location_on) : Icon(Icons.location_off),
onPressed: () => _liveUpdate = !_liveUpdate,
child: _liveUpdate ? Icon(Icons.location_on) : Icon(Icons.location_off),
),
);
}
Expand Down
3 changes: 2 additions & 1 deletion example/lib/widgets/drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ Drawer buildDrawer(BuildContext context, String currentRoute) {
title: const Text('Tile loading error handle'),
selected: currentRoute == TileLoadingErrorHandle.route,
onTap: () {
Navigator.pushReplacementNamed(context, TileLoadingErrorHandle.route);
Navigator.pushReplacementNamed(
context, TileLoadingErrorHandle.route);
},
),
],
Expand Down
1 change: 0 additions & 1 deletion lib/src/layer/group_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class GroupLayer extends StatelessWidget {
return StreamBuilder(
stream: stream,
builder: (BuildContext context, _) {

var layers = <Widget>[
for (var options in groupOpts.group) _createLayer(options)
];
Expand Down
15 changes: 10 additions & 5 deletions lib/src/layer/tile_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,9 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {
);
}

setState(() {});
if (mounted) {
setState(() {});
}

if (_noTilesToLoad()) {
// Wait a bit more than tileFadeInDuration (the duration of the tile fade-in)
Expand All @@ -970,7 +972,9 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {
? options.tileFadeInDuration + const Duration(milliseconds: 50)
: const Duration(milliseconds: 50),
() {
setState(_pruneTiles);
if (mounted) {
setState(_pruneTiles);
}
},
);
}
Expand Down Expand Up @@ -1082,13 +1086,12 @@ class Tile implements Comparable<Tile> {
}

animationController?.removeStatusListener(_onAnimateEnd);
animationController?.dispose();
_imageStream?.removeListener(_listener);
}

void startFadeInAnimation(Duration duration, TickerProvider vsync,
{double from}) {
animationController?.removeStatusListener(_onAnimateEnd);

animationController = AnimationController(duration: duration, vsync: vsync)
..addStatusListener(_onAnimateEnd);

Expand Down Expand Up @@ -1197,7 +1200,9 @@ class _AnimatedTileState extends State<AnimatedTile> {
}

void _handleChange() {
setState(() {});
if (mounted) {
setState(() {});
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions lib/src/layer/tile_provider/mbtiles_image_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ class MBTileImage extends ImageProvider<MBTileImage> {

@override
bool operator ==(other) {
return other is MBTileImage && coords == other.coords
&& filePath == other.filePath;
return other is MBTileImage &&
coords == other.coords &&
filePath == other.filePath;
}
}
3 changes: 1 addition & 2 deletions lib/src/map/flutter_map_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ class FlutterMapState extends MapGestureMixin {
assert(false, """
Can't find correct layer for $options. Perhaps when you create your FlutterMap you need something like this:
options: new MapOptions(plugins: [MyFlutterMapPlugin()])"""
);
options: new MapOptions(plugins: [MyFlutterMapPlugin()])""");
return null;
}
}

0 comments on commit 9d64fac

Please sign in to comment.