Skip to content

Commit

Permalink
feature : add CustomTile to MapControllerHook
Browse files Browse the repository at this point in the history
  • Loading branch information
liodali committed Jan 3, 2023
1 parent 03d1def commit cca5a3b
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions lib/src/osm_hook.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_osm_plugin/flutter_osm_plugin.dart';

/// [MapControllerHook]
///
///
/// this controller hook is to illustrate statefull widget for hooks
/// where the [MapController] will be initialized
class MapControllerHook extends Hook<MapController> {
final bool initMapWithUserPosition;
final GeoPoint? initPosition;
final BoundingBox? areaLimit;

const MapControllerHook({
this.initMapWithUserPosition = false,
this.initPosition,
this.areaLimit,
});
final CustomTile? tile;
const MapControllerHook(
{this.initMapWithUserPosition = false,
this.initPosition,
this.areaLimit,
this.tile});

@override
HookState<MapController, Hook<MapController>> createState() =>
Expand All @@ -28,11 +29,20 @@ class _MapControllerHookState
@override
void initHook() {
super.initHook();
_controller = MapController(
initMapWithUserPosition: hook.initMapWithUserPosition,
initPosition: hook.initPosition,
areaLimit: hook.areaLimit,
);
if (hook.tile == null) {
_controller = MapController(
initMapWithUserPosition: hook.initMapWithUserPosition,
initPosition: hook.initPosition,
areaLimit: hook.areaLimit,
);
} else if (hook.tile != null) {
_controller = MapController.customLayer(
initMapWithUserPosition: hook.initMapWithUserPosition,
initPosition: hook.initPosition,
areaLimit: hook.areaLimit,
customTile: hook.tile!,
);
}
}

@override
Expand All @@ -47,8 +57,9 @@ class _MapControllerHookState
}

typedef MapIsReady = Function();

/// [MapIsReadyHook]
///
///
/// this hook is to replace MapIsReady for hook state
/// where you can put your logic after the map is ready to use
class MapIsReadyHook extends Hook<MapIsReady> {
Expand Down

0 comments on commit cca5a3b

Please sign in to comment.