Center map on user location
All checks were successful
Build and deploy Flutter Web / build (push) Successful in 2m28s

This commit is contained in:
Ruslan Bakiev
2026-05-08 20:23:15 +07:00
parent f388b7a3d2
commit 929d3a46d3
11 changed files with 243 additions and 20 deletions

View File

@@ -39,13 +39,15 @@ class MapflowShell extends ConsumerWidget {
class _MapContent extends ConsumerWidget {
const _MapContent({required this.state});
static const _center = LatLng(10.7718, 106.6982);
static const _fallbackCenter = LatLng(10.7718, 106.6982);
final PlaceState state;
@override
Widget build(BuildContext context, WidgetRef ref) {
final selected = state.selectedPlace;
final userCoordinate = state.userCoordinate;
final mapCenter = userCoordinate ?? selected?.coordinate ?? _fallbackCenter;
final availableTraits = {
for (final place in state.recommendations) ...place.traits,
}.toList();
@@ -55,7 +57,7 @@ class _MapContent extends ConsumerWidget {
children: [
FlutterMap(
options: MapOptions(
initialCenter: selected?.coordinate ?? _center,
initialCenter: mapCenter,
initialZoom: 14.2,
minZoom: 3,
maxZoom: 18,
@@ -76,6 +78,13 @@ class _MapContent extends ConsumerWidget {
.selectPlace(place.id),
),
),
if (userCoordinate != null)
Marker(
width: 30,
height: 30,
point: userCoordinate,
child: const _UserLocationMarker(),
),
],
),
const _MapAttribution(),
@@ -122,7 +131,10 @@ class _MapContent extends ConsumerWidget {
child: Padding(
padding: const EdgeInsets.only(right: 12),
child: FloatingActionButton(
onPressed: () => _openAddFlow(context, selected?.coordinate),
onPressed: () => _openAddFlow(
context,
userCoordinate ?? selected?.coordinate,
),
child: const Icon(Icons.add_location_alt_outlined),
),
),
@@ -138,7 +150,7 @@ class _MapContent extends ConsumerWidget {
MaterialPageRoute<void>(
fullscreenDialog: true,
builder: (_) => AddExperienceFlow(
coordinate: coordinate ?? _center,
coordinate: coordinate ?? _fallbackCenter,
hasTelegramAuth: state.hasTelegramAuth,
),
),
@@ -146,6 +158,32 @@ class _MapContent extends ConsumerWidget {
}
}
class _UserLocationMarker extends StatelessWidget {
const _UserLocationMarker();
@override
Widget build(BuildContext context) {
final color = Theme.of(context).colorScheme.primary;
return DecoratedBox(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: color.withValues(alpha: 0.18),
),
child: Center(
child: Container(
width: 14,
height: 14,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: color,
border: Border.all(color: Colors.white, width: 3),
),
),
),
);
}
}
class _UserAvatar extends StatelessWidget {
const _UserAvatar({required this.user, required this.onLogout});
@@ -403,20 +441,7 @@ class _MapLoading extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
FlutterMap(
options: const MapOptions(
initialCenter: LatLng(10.7718, 106.6982),
initialZoom: 14.2,
),
children: [const _BaseMapTileLayer(), const _MapAttribution()],
),
const Center(child: CircularProgressIndicator()),
],
),
);
return const Scaffold(body: Center(child: CircularProgressIndicator()));
}
}