Skip to content

Commit

Permalink
TICKET-B-3150: Fix for blank screen on back button exit on Android (#153
Browse files Browse the repository at this point in the history
)

Signed-off-by: Rahul Pant <[email protected]>
  • Loading branch information
mr-pant authored May 22, 2024
1 parent b4ad039 commit 3df8e6b
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions lib/landing_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class _LandingScreenState extends State<LandingScreen> with Positioning, Widgets
ConsentUserReply? _consentState;
MapMarker? _routeFromMarker;
Place? _routeFromPlace;
MapCameraState? _cameraState;

@override
void initState() {
Expand All @@ -98,13 +99,23 @@ class _LandingScreenState extends State<LandingScreen> with Positioning, Widgets
if (state == AppLifecycleState.detached) {
// This flag helps us to re-init the positioning when app is resumed.
_didBackPressedAndPositionStopped = true;
if (Platform.isAndroid) {
_cameraState = _hereMapController.camera.state;
}
stopPositioning();
} else if (state == AppLifecycleState.resumed && _didBackPressedAndPositionStopped) {
_didBackPressedAndPositionStopped = false;
// Restart the location engine and initiate positioning when the app is resumed.
_positioningEngine.initLocationEngine(context: context).then((value) {
initPositioning(context: context, hereMapController: _hereMapController);
});

// Rebuilding the HereMap widget when the app is resumed after it was detached via back button
// this is a workaround to fix the issue of blank PlatformView on Android during app resume
// Ref: https://github.com/flutter/flutter/issues/148662
if (Platform.isAndroid) {
setState(() => _hereMapKey = GlobalKey());
}
}
}

Expand Down Expand Up @@ -145,10 +156,19 @@ class _LandingScreenState extends State<LandingScreen> with Positioning, Widgets
return;
}

hereMapController.camera.lookAtPointWithMeasure(
Positioning.initPosition,
MapMeasure(MapMeasureKind.distance, Positioning.initDistanceToEarth),
);
if (_cameraState != null) {
_hereMapController.camera.lookAtPointWithGeoOrientationAndMeasure(
_cameraState!.targetCoordinates,
GeoOrientationUpdate(_cameraState!.orientationAtTarget.bearing, _cameraState!.orientationAtTarget.tilt),
MapMeasure(MapMeasureKind.distance, _cameraState!.distanceToTargetInMeters),
);
_cameraState = null;
} else {
hereMapController.camera.lookAtPointWithMeasure(
Positioning.initPosition,
MapMeasure(MapMeasureKind.distance, Positioning.initDistanceToEarth),
);
}

hereMapController.setWatermarkLocation(
Anchor2D.withHorizontalAndVertical(0, 1),
Expand Down

0 comments on commit 3df8e6b

Please sign in to comment.