From cb7eb89b51a703eda7f8b593cbac98d45d0298d7 Mon Sep 17 00:00:00 2001 From: Maximilian Ammann Date: Sun, 23 Jan 2022 12:30:38 +0100 Subject: [PATCH 01/10] Reenable orientation change and add a workaround for android --- .../android/app/src/main/AndroidManifest.xml | 2 +- frontend/lib/map/map/map.dart | 18 +++++-- .../lib/map/map/screen_parent_resizer.dart | 53 +++++++++++++++++++ 3 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 frontend/lib/map/map/screen_parent_resizer.dart diff --git a/frontend/android/app/src/main/AndroidManifest.xml b/frontend/android/app/src/main/AndroidManifest.xml index d2594cd2a..56d5f7528 100644 --- a/frontend/android/app/src/main/AndroidManifest.xml +++ b/frontend/android/app/src/main/AndroidManifest.xml @@ -12,7 +12,7 @@ implements MapController { MaplibreMapController? _controller; Symbol? _symbol; bool _permissionGiven = false; - Stack? _mapboxView; + Widget? _currentMapLibreView; bool _isAnimating = false; @override @@ -59,13 +61,16 @@ class _MapState extends State implements MapController { final pixelRatio = MediaQuery.of(context).devicePixelRatio; final compassMargin = Platform.isIOS ? statusBarHeight / pixelRatio : statusBarHeight * pixelRatio; - if (_mapboxView == null || !_isAnimating) { + final Widget? currentMapLibreView = _currentMapLibreView; + final Widget maplibreView; + + if (currentMapLibreView == null || !_isAnimating) { final userLocation = widget.userLocation; final cameraPosition = userLocation != null ? CameraPosition(target: userLocation, zoom: Map.userLocationZoomLevel) : const CameraPosition(target: Map.centerOfBavaria, zoom: Map.bavariaZoomLevel); - _mapboxView = Stack( + maplibreView = Stack( children: [ MaplibreMap( initialCameraPosition: cameraPosition, @@ -106,8 +111,13 @@ class _MapState extends State implements MapController { ), ], ); + } else { + maplibreView = currentMapLibreView; } - return _mapboxView ?? Container(); + + // Apply ScreenParentResizer only on android + // https://github.com/flutter-mapbox-gl/maps/issues/195 + return defaultTargetPlatform == TargetPlatform.android ? ScreenParentResizer(child: maplibreView) : maplibreView; } void _onMapCreated(MaplibreMapController controller) { diff --git a/frontend/lib/map/map/screen_parent_resizer.dart b/frontend/lib/map/map/screen_parent_resizer.dart new file mode 100644 index 000000000..7a3b55616 --- /dev/null +++ b/frontend/lib/map/map/screen_parent_resizer.dart @@ -0,0 +1,53 @@ +import 'dart:math'; +import 'package:flutter/material.dart'; + +/// A widget which resizes the child widget twice when the orientation changes. +/// +/// * Firstly, the child is resized to +/// `width = height = max(screenWidth, screenHeight)`. This creates a square. +/// * Secondly, the child is resized to +/// `width = parentWidth, height = parentHeight. This sizes the child according to the parent constraints. +class ScreenParentResizer extends StatefulWidget { + final Widget? child; + + const ScreenParentResizer({ + Key? key, + required Widget this.child, + }) : super(key: key); + + @override + State createState() => _ScreenParentResizer(); +} + +class _ScreenParentResizer extends State { + Orientation? _lastBuildOrientation; + + @override + Widget build(BuildContext context) { + final maximum = max( + MediaQuery.of(context).size.width, + MediaQuery.of(context).size.height, + ); + + final currentOrientation = MediaQuery.of(context).orientation; + final isOverDrawingSquare = currentOrientation != _lastBuildOrientation; + + if (isOverDrawingSquare) { + WidgetsBinding.instance!.addPostFrameCallback( + (_) => setState(() { + _lastBuildOrientation = currentOrientation; + }), + ); + } + + final width = isOverDrawingSquare ? maximum : null; + final height = isOverDrawingSquare ? maximum : null; + + return OverflowBox( + alignment: Alignment.topLeft, + maxHeight: height, + maxWidth: width, + child: widget.child, + ); + } +} From b8363ca82f9db2c6e06ab2ea4d616a7293e21dd8 Mon Sep 17 00:00:00 2001 From: Maximilian Ammann Date: Sun, 23 Jan 2022 12:31:02 +0100 Subject: [PATCH 02/10] Set max line width to 120 --- .idea/codeStyles/Project.xml | 3 +++ .idea/codeStyles/codeStyleConfig.xml | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index e3e66c43e..e8b634e73 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -7,6 +7,9 @@ + +