Skip to content

Commit

Permalink
fix: LateInitializationError when specifying initialCameraFit (#1691
Browse files Browse the repository at this point in the history
)
  • Loading branch information
TesteurManiak authored Oct 23, 2023
1 parent d9c9210 commit 83d773d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
12 changes: 7 additions & 5 deletions lib/src/gestures/flutter_map_interactive_viewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ import 'package:flutter_map/src/map/options/options.dart';
import 'package:flutter_map/src/misc/point_extensions.dart';
import 'package:latlong2/latlong.dart';

typedef InteractiveViewerBuilder = Widget Function(
BuildContext context,
MapOptions options,
MapCamera camera,
);

/// Applies interactions (gestures/scroll/taps etc) to the current [MapCamera]
/// via the internal [controller].
class FlutterMapInteractiveViewer extends StatefulWidget {
final Widget Function(
BuildContext context,
MapOptions options,
MapCamera camera,
) builder;
final InteractiveViewerBuilder builder;
final FlutterMapInternalController controller;

const FlutterMapInteractiveViewer({
Expand Down
2 changes: 1 addition & 1 deletion lib/src/map/options/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class MapOptions {
/// and you need to access the controller as soon as the map is built.
/// Otherwise you can use WidgetsBinding.instance.addPostFrameCallback
/// In initState to controll the map before the next frame.
final void Function()? onMapReady;
final VoidCallback? onMapReady;

final LatLngBounds? maxBounds;

Expand Down
3 changes: 2 additions & 1 deletion lib/src/map/widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ class _FlutterMapStateContainer extends State<FlutterMap>
return LayoutBuilder(
builder: (context, constraints) {
_updateAndEmitSizeIfConstraintsChanged(constraints);
_applyInitialCameraFit(constraints);

return FlutterMapInteractiveViewer(
controller: _flutterMapInternalController,
Expand Down Expand Up @@ -235,6 +234,8 @@ class _FlutterMapStateContainer extends State<FlutterMap>
oldCamera,
newMapCamera,
);

_applyInitialCameraFit(constraints);
}
});
}
Expand Down

0 comments on commit 83d773d

Please sign in to comment.