Skip to content

Commit

Permalink
Add temporary debugPrints to highlight race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
rorystephenson committed Mar 30, 2023
1 parent 2c8dcde commit 833fe74
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
13 changes: 12 additions & 1 deletion lib/src/layer/tile_layer/tile_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,16 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {
}

if (reloadTiles) {
_updateTilesInVisibleBounds(mapState);
if (mapState.size == const CustomPoint(0, 0)) {
debugPrint('Size is zero, scheduling update in next frame.');
WidgetsBinding.instance.addPostFrameCallback((_) {
debugPrint('Post-frame callback update, size is: ${mapState.size}');
_updateTilesInVisibleBounds(mapState);
});
} else {
debugPrint('Size is non-zero, triggering update.');
_updateTilesInVisibleBounds(mapState);
}
}

_initializedFromMapState = true;
Expand Down Expand Up @@ -468,6 +477,7 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {
@override
Widget build(BuildContext context) {
final map = FlutterMapState.maybeOf(context)!;
debugPrint('TileLayer build (map size ${map.size})');

if (_outsideZoomLimits(map.zoom.round())) return const SizedBox.shrink();

Expand Down Expand Up @@ -529,6 +539,7 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {

// Load new tiles in the visible bounds and prune those outside.
void _updateTilesInVisibleBounds(FlutterMapState mapState) {
debugPrint('Updating tiles, map size: ${mapState.size}');
final tileZoom = _clampToNativeZoom(mapState.zoom);
if (!_outsideZoomLimits(tileZoom)) {
_loadTilesAndMarkForPruning(
Expand Down
8 changes: 6 additions & 2 deletions lib/src/map/flutter_map_state.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import 'dart:math' as math;

import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map/src/core/bounds.dart';
import 'package:flutter_map/src/gestures/gestures.dart';
import 'package:flutter_map/src/map/map.dart';
import 'package:flutter_map/src/map/map_state_widget.dart';
import 'package:latlong2/latlong.dart';
import 'dart:math' as math;
import 'package:flutter_map/src/core/bounds.dart';

class FlutterMapState extends MapGestureMixin
with AutomaticKeepAliveClientMixin {
Expand Down Expand Up @@ -42,6 +43,7 @@ class FlutterMapState extends MapGestureMixin
_bounds = _calculateBounds();

WidgetsBinding.instance.addPostFrameCallback((_) {
debugPrint('FlutterMapState post frame callback (calling onMapReady)');
options.onMapReady?.call();
});
}
Expand Down Expand Up @@ -158,6 +160,8 @@ class FlutterMapState extends MapGestureMixin
return LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
//Update on layout change
debugPrint(
'FlutterMapState LayoutBuilder set size: (${constraints.maxWidth}, ${constraints.maxHeight})');
setSize(constraints.maxWidth, constraints.maxHeight);

if (options.bounds != null &&
Expand Down

0 comments on commit 833fe74

Please sign in to comment.