Launch add review through URL route params
Build and deploy Flutter Web / build (push) Successful in 2m30s

This commit is contained in:
Ruslan Bakiev
2026-06-13 00:46:55 +07:00
parent dedde2deea
commit e641837815
2 changed files with 50 additions and 21 deletions
+49 -19
View File
@@ -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<void>(
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<String, String> 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);
}