Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG_UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@
actions such as selecting a POI or starting navigation from outside the map screen (e.g., from a
list or a notification). Since the MapViewController is only available once the MapView has fully
loaded, this helper provides a simple, awaitable ensureMapViewController() method—powered by a
Dart Completer—that resolves automatically when the controller becomes ready.
Dart Completer—that resolves automatically when the controller becomes ready.

### Added

- Added new message to let map-viewer know what's the current device preferred color scheme.
23 changes: 22 additions & 1 deletion lib/src/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ class MapViewController {
_webViewController.reload();
}

/// Sets the viewer `preferredTheme` according to the current platform brightness.
///
/// This does not override a theme already selected by the user inside the
/// webview; it only provides the preferred theme when the viewer applies system
/// preferences.
void _setPreferredTheme(Brightness brightness) {
_sendPreferredTheme(brightness);
}

/// Selects the given Building in the map.
/// To set the initial Building use [MapViewConfiguration].
void selectBuilding(String identifier) async {
Expand Down Expand Up @@ -272,7 +281,8 @@ class MapViewController {
/// Select a floor of the current building by its [Floor.identifier].
///
/// **NOTE**: introducing an invalid identifier may result in unexpected behaviours.
void selectFloor(String identifier, {SelectCartographyOptions? options}) async {
void selectFloor(String identifier,
{SelectCartographyOptions? options}) async {
int floorId = int.tryParse(identifier) ?? 0;
final message = {
"identifier": floorId,
Expand Down Expand Up @@ -347,6 +357,17 @@ class MapViewController {
_sendMessage(WV_APP_CONFIG, jsonEncode(configItems));
}

void _sendPreferredTheme(Brightness brightness) {
dynamic message = {
"theme": brightness == Brightness.dark ? 'dark' : 'light'
};

_sendMessage(
WV_MESSAGE_UI_SET_PREFERRED_THEME,
jsonEncode(message),
);
}

void _setRoute(
DirectionsMessage directionsMessage, SitumRoute situmRoute) async {
situmRoute.rawContent["identifier"] = directionsMessage.identifier;
Expand Down
18 changes: 16 additions & 2 deletions lib/src/situm_map_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class MapView extends StatefulWidget {
State<StatefulWidget> createState() => _MapViewState();
}

class _MapViewState extends State<MapView> {
class _MapViewState extends State<MapView> with WidgetsBindingObserver {
static MapViewController? wyfController;
static PlatformWebViewController? webViewController;
static PlatformWebViewWidget? webViewWidget;
Expand All @@ -44,6 +44,7 @@ class _MapViewState extends State<MapView> {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
mapViewConfiguration = widget.configuration;

// Avoid re-initializations of the underlying WebView (PlatformView) if
Expand Down Expand Up @@ -176,6 +177,12 @@ class _MapViewState extends State<MapView> {
?.loadRequest(LoadRequestParams(uri: Uri.parse(mapViewUrl)));
}

void _syncPlatformPreferredTheme() {
wyfController?._setPreferredTheme(
WidgetsBinding.instance.platformDispatcher.platformBrightness,
);
}

void _displayBlankScreen(bool value) {
if (mounted) {
setState(() {
Expand Down Expand Up @@ -221,16 +228,22 @@ class _MapViewState extends State<MapView> {
}
}

@override
void didChangePlatformBrightness() {
_syncPlatformPreferredTheme();
}

@override
void dispose() {
super.dispose();
WidgetsBinding.instance.removeObserver(this);
// IMPORTANT: We use a static reference to support the
// "persistUnderlyingWidget" feature. Because of that, this state must be
// explicitly unregistered when disposed; otherwise it may continue receiving
// WebView messages through _onMapViewerMessageUpdateInternalState, causing
// unwanted rebuilds in an inconsistent state.
_InternalMessageBridge.unregister();
// wyfController?.onWidgetDisposed();
super.dispose();
Comment thread
Daamii marked this conversation as resolved.
}

void _onErrorRetryLoad() {
Expand All @@ -255,6 +268,7 @@ class _MapViewState extends State<MapView> {
_shouldDisplayMainFrameError = false;
}
});
_syncPlatformPreferredTheme();
}
}
}
1 change: 1 addition & 0 deletions lib/wayfinding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const WV_MESSAGE_CALIBRATION_STOPPED = "calibration.stopped";

// Configuration
const WV_APP_CONFIG = "app.set_config_item";
const WV_MESSAGE_UI_SET_PREFERRED_THEME = "ui.set_preferred_theme";
const WV_APP_CONFIG_ITEM_TTS_ENGINE = "internal.tts.engine";

// Location actions
Expand Down