From e6418378153701f22e2d481bdd6bfa9f3874a086 Mon Sep 17 00:00:00 2001 From: Ruslan Bakiev <572431+veikab@users.noreply.github.com> Date: Sat, 13 Jun 2026 00:46:55 +0700 Subject: [PATCH] Launch add review through URL route params --- lib/app/router/app_router.dart | 68 +++++++++++++------ .../mapflow/presentation/mapflow_shell.dart | 3 +- 2 files changed, 50 insertions(+), 21 deletions(-) diff --git a/lib/app/router/app_router.dart b/lib/app/router/app_router.dart index 560ded7..07d18f1 100644 --- a/lib/app/router/app_router.dart +++ b/lib/app/router/app_router.dart @@ -5,37 +5,48 @@ import 'package:latlong2/latlong.dart'; import '../../features/mapflow/presentation/admin_voice_experiences_screen.dart'; import '../../features/mapflow/presentation/mapflow_shell.dart'; -class AddExperienceArgs { - const AddExperienceArgs({ - required this.coordinate, - required this.hasTelegramAuth, - }); +class MapflowRoutes { + const MapflowRoutes._(); - final LatLng? coordinate; - final bool hasTelegramAuth; + static const home = '/'; + static const addExperience = '/experience/new'; + static const adminReviews = '/admin/reviews'; + + static String addExperienceLocation({ + required LatLng? coordinate, + required bool hasTelegramAuth, + }) { + return Uri( + path: addExperience, + queryParameters: { + 'telegramAuth': hasTelegramAuth ? '1' : '0', + if (coordinate != null) ...{ + 'lat': coordinate.latitude.toString(), + 'lng': coordinate.longitude.toString(), + }, + }, + ).toString(); + } } GoRouter createAppRouter() { return GoRouter( errorBuilder: (context, state) => const MapflowShell(), routes: [ - GoRoute(path: '/', builder: (context, state) => const MapflowShell()), GoRoute( - path: '/experience/new', + path: MapflowRoutes.home, + builder: (context, state) => const MapflowShell(), + ), + GoRoute( + path: MapflowRoutes.addExperience, pageBuilder: (context, state) { - final extra = state.extra; - final args = extra is AddExperienceArgs - ? extra - : const AddExperienceArgs( - coordinate: null, - hasTelegramAuth: true, - ); + final queryParameters = state.uri.queryParameters; return CustomTransitionPage( fullscreenDialog: true, key: state.pageKey, child: AddExperienceFlow( - coordinate: args.coordinate, - hasTelegramAuth: args.hasTelegramAuth, + coordinate: _coordinateFromQuery(queryParameters), + hasTelegramAuth: queryParameters['telegramAuth'] != '0', ), transitionsBuilder: (context, animation, _, child) { return SlideTransition( @@ -50,9 +61,28 @@ GoRouter createAppRouter() { }, ), GoRoute( - path: '/admin/reviews', + path: MapflowRoutes.adminReviews, builder: (context, state) => const AdminVoiceExperiencesScreen(), ), ], ); } + +LatLng? _coordinateFromQuery(Map queryParameters) { + final lat = queryParameters['lat']; + final lng = queryParameters['lng']; + if (lat == null && lng == null) { + return null; + } + if (lat == null || lng == null) { + throw StateError('Both lat and lng query parameters are required.'); + } + + final latitude = double.parse(lat); + final longitude = double.parse(lng); + if (!latitude.isFinite || !longitude.isFinite) { + throw StateError('Review coordinate query parameters must be finite.'); + } + + return LatLng(latitude, longitude); +} diff --git a/lib/features/mapflow/presentation/mapflow_shell.dart b/lib/features/mapflow/presentation/mapflow_shell.dart index bef6f0f..49f1ec6 100644 --- a/lib/features/mapflow/presentation/mapflow_shell.dart +++ b/lib/features/mapflow/presentation/mapflow_shell.dart @@ -165,8 +165,7 @@ class _MapContent extends StatelessWidget { void _openAddFlow(BuildContext context, LatLng? coordinate) { context.push( - '/experience/new', - extra: AddExperienceArgs( + MapflowRoutes.addExperienceLocation( coordinate: coordinate, hasTelegramAuth: state.hasTelegramAuth, ),