@ -11,7 +11,6 @@ import 'package:immich_mobile/extensions/maplibrecontroller_extensions.dart';
import ' package:immich_mobile/modules/map/widgets/map_theme_override.dart ' ;
import ' package:maplibre_gl/maplibre_gl.dart ' ;
import ' package:immich_mobile/modules/map/utils/map_utils.dart ' ;
import ' package:geolocator/geolocator.dart ' ;
@ RoutePage < LatLng ? > ( )
class MapLocationPickerPage extends HookConsumerWidget {
@ -46,15 +45,13 @@ class MapLocationPickerPage extends HookConsumerWidget {
}
Future < void > getCurrentLocation ( ) async {
var ( currentLocation , locationPermission ) =
var ( currentLocation , _ ) =
await MapUtils . checkPermAndGetLocation ( context ) ;
if ( locationPermission = = LocationPermission . denied | |
locationPermission = = LocationPermission . deniedForever ) {
return ;
}
if ( currentLocation = = null ) {
return ;
}
var currentLatLng =
LatLng ( currentLocation . latitude , currentLocation . longitude ) ;
selectedLatLng . value = currentLatLng ;
@ -67,40 +64,35 @@ class MapLocationPickerPage extends HookConsumerWidget {
backgroundColor: ctx . themeData . cardColor ,
appBar: _AppBar ( onClose: onClose ) ,
extendBodyBehindAppBar: true ,
body: Column (
children: [
style . widgetWhen (
onData: ( style ) = > Expanded (
child: Container (
clipBehavior: Clip . antiAliasWithSaveLayer ,
decoration: const BoxDecoration (
borderRadius: BorderRadius . only (
bottomLeft: Radius . circular ( 40 ) ,
bottomRight: Radius . circular ( 40 ) ,
) ,
) ,
child: MaplibreMap (
initialCameraPosition:
CameraPosition ( target: initialLatLng , zoom: 12 ) ,
styleString: style ,
onMapCreated: ( mapController ) = >
controller . value = mapController ,
onStyleLoadedCallback: onStyleLoaded ,
onMapClick: onMapClick ,
dragEnabled: false ,
tiltGesturesEnabled: false ,
myLocationEnabled: false ,
attributionButtonMargins: const Point ( 20 , 15 ) ,
) ,
) ,
primary: true ,
body: style . widgetWhen (
onData: ( style ) = > Container (
clipBehavior: Clip . antiAliasWithSaveLayer ,
decoration: const BoxDecoration (
borderRadius: BorderRadius . only (
bottomLeft: Radius . circular ( 40 ) ,
bottomRight: Radius . circular ( 40 ) ,
) ,
) ,
_BottomBar (
selectedLatLng: selectedLatLng ,
onUseLocation: ( ) = > onClose ( selectedLatLng . value ) ,
onGetCurrentLocation: getCurrentLocation ,
child: MaplibreMap (
initialCameraPosition:
CameraPosition ( target: initialLatLng , zoom: 12 ) ,
styleString: style ,
onMapCreated: ( mapController ) = >
controller . value = mapController ,
onStyleLoadedCallback: onStyleLoaded ,
onMapClick: onMapClick ,
dragEnabled: false ,
tiltGesturesEnabled: false ,
myLocationEnabled: false ,
attributionButtonMargins: const Point ( 20 , 15 ) ,
) ,
] ,
) ,
) ,
bottomNavigationBar: _BottomBar (
selectedLatLng: selectedLatLng ,
onUseLocation: ( ) = > onClose ( selectedLatLng . value ) ,
onGetCurrentLocation: getCurrentLocation ,
) ,
) ,
) ,
@ -116,17 +108,15 @@ class _AppBar extends StatelessWidget implements PreferredSizeWidget {
@ override
Widget build ( BuildContext context ) {
return Padding (
padding: EdgeInsets . only ( top: MediaQuery . paddingOf ( context ) . top + 25 ) ,
child: Expanded (
child: Align (
alignment: Alignment . centerLeft ,
child: ElevatedButton (
onPressed: onClose ,
style: ElevatedButton . styleFrom (
shape: const CircleBorder ( ) ,
) ,
child: const Icon ( Icons . arrow_back_ios_new_rounded ) ,
padding: const EdgeInsets . only ( top: 25 ) ,
child: Align (
alignment: Alignment . centerLeft ,
child: ElevatedButton (
onPressed: onClose ,
style: ElevatedButton . styleFrom (
shape: const CircleBorder ( ) ,
) ,
child: const Icon ( Icons . arrow_back_ios_new_rounded ) ,
) ,
) ,
) ;
@ -150,38 +140,42 @@ class _BottomBar extends StatelessWidget {
@ override
Widget build ( BuildContext context ) {
return SizedBox (
height: 150 ,
child: Column (
mainAxisAlignment: MainAxisAlignment . spaceEvenly ,
crossAxisAlignment: CrossAxisAlignment . start ,
children: [
Row (
mainAxisAlignment: MainAxisAlignment . center ,
children: [
const Icon ( Icons . public , size: 18 ) ,
const SizedBox ( width: 15 ) ,
ValueListenableBuilder (
valueListenable: selectedLatLng ,
builder: ( _ , value , __ ) = > Text (
" ${ value . latitude . toStringAsFixed ( 4 ) } , ${ value . longitude . toStringAsFixed ( 4 ) } " ,
height: 150 + context . padding . bottom ,
child: Padding (
padding: EdgeInsets . only ( bottom: context . padding . bottom ) ,
child: Column (
mainAxisAlignment: MainAxisAlignment . spaceEvenly ,
crossAxisAlignment: CrossAxisAlignment . start ,
children: [
Row (
mainAxisAlignment: MainAxisAlignment . center ,
children: [
const Icon ( Icons . public , size: 18 ) ,
const SizedBox ( width: 15 ) ,
ValueListenableBuilder (
valueListenable: selectedLatLng ,
builder: ( _ , value , __ ) = > Text (
" ${ value . latitude . toStringAsFixed ( 4 ) } , ${ value . longitude . toStringAsFixed ( 4 ) } " ,
) ,
) ,
) ,
] ,
) ,
Row (
mainAxisAlignment: MainAxisAlignment . spaceEvenly ,
children: [
ElevatedButton (
onPressed: onUseLocation ,
child: const Text ( " map_location_picker_page_use_location " ) . tr ( ) ,
) ,
ElevatedButton (
onPressed: onGetCurrentLocation ,
child: const Icon ( Icons . my_location ) ,
) ,
] ,
) ,
] ,
] ,
) ,
Row (
mainAxisAlignment: MainAxisAlignment . spaceEvenly ,
children: [
ElevatedButton (
onPressed: onUseLocation ,
child:
const Text ( " map_location_picker_page_use_location " ) . tr ( ) ,
) ,
ElevatedButton (
onPressed: onGetCurrentLocation ,
child: const Icon ( Icons . my_location ) ,
) ,
] ,
) ,
] ,
) ,
) ,
) ;
}