-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
491fff6
commit 206116c
Showing
14 changed files
with
420 additions
and
265 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
mobile/lib/modules/asset_viewer/providers/current_asset.provider.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
mobile/lib/modules/map/views/map_location_picker_page.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
import 'dart:math'; | ||
|
||
import 'package:auto_route/auto_route.dart'; | ||
import 'package:easy_localization/easy_localization.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_hooks/flutter_hooks.dart'; | ||
import 'package:hooks_riverpod/hooks_riverpod.dart'; | ||
import 'package:immich_mobile/extensions/asyncvalue_extensions.dart'; | ||
import 'package:immich_mobile/extensions/build_context_extensions.dart'; | ||
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'; | ||
|
||
class MapLocationPickerPage extends HookConsumerWidget { | ||
final LatLng initialLatLng; | ||
|
||
const MapLocationPickerPage({ | ||
super.key, | ||
this.initialLatLng = const LatLng(0, 0), | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
final selectedLatLng = useValueNotifier<LatLng>(initialLatLng); | ||
final controller = useRef<MaplibreMapController?>(null); | ||
final marker = useRef<Symbol?>(null); | ||
|
||
Future<void> onStyleLoaded() async { | ||
marker.value = await controller.value?.addMarkerAtLatLng(initialLatLng); | ||
} | ||
|
||
Future<void> onMapClick(Point<num> point, LatLng centre) async { | ||
selectedLatLng.value = centre; | ||
controller.value?.animateCamera(CameraUpdate.newLatLng(centre)); | ||
if (marker.value != null) { | ||
await controller.value | ||
?.updateSymbol(marker.value!, SymbolOptions(geometry: centre)); | ||
} | ||
} | ||
|
||
void onClose([LatLng? selected]) { | ||
context.popRoute(selected); | ||
} | ||
|
||
return MapThemeOveride( | ||
mapBuilder: (style) => Builder( | ||
builder: (ctx) => Scaffold( | ||
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), | ||
), | ||
), | ||
), | ||
), | ||
_BottomBar( | ||
selectedLatLng: selectedLatLng, | ||
onUseLocation: () => onClose(selectedLatLng.value), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} | ||
|
||
class _AppBar extends StatelessWidget implements PreferredSizeWidget { | ||
final Function() onClose; | ||
|
||
const _AppBar({required this.onClose}); | ||
|
||
@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), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
|
||
@override | ||
Size get preferredSize => const Size.fromHeight(100); | ||
} | ||
|
||
class _BottomBar extends StatelessWidget { | ||
final ValueNotifier<LatLng> selectedLatLng; | ||
final Function() onUseLocation; | ||
|
||
const _BottomBar({ | ||
required this.selectedLatLng, | ||
required this.onUseLocation, | ||
}); | ||
|
||
@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)}", | ||
), | ||
), | ||
], | ||
), | ||
Center( | ||
child: ElevatedButton( | ||
onPressed: onUseLocation, | ||
child: const Text("map_location_picker_page_use_location").tr(), | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.