Launch add review through URL route params
Build and deploy Flutter Web / build (push) Successful in 2m30s
Build and deploy Flutter Web / build (push) Successful in 2m30s
This commit is contained in:
@@ -5,37 +5,48 @@ import 'package:latlong2/latlong.dart';
|
|||||||
import '../../features/mapflow/presentation/admin_voice_experiences_screen.dart';
|
import '../../features/mapflow/presentation/admin_voice_experiences_screen.dart';
|
||||||
import '../../features/mapflow/presentation/mapflow_shell.dart';
|
import '../../features/mapflow/presentation/mapflow_shell.dart';
|
||||||
|
|
||||||
class AddExperienceArgs {
|
class MapflowRoutes {
|
||||||
const AddExperienceArgs({
|
const MapflowRoutes._();
|
||||||
required this.coordinate,
|
|
||||||
required this.hasTelegramAuth,
|
|
||||||
});
|
|
||||||
|
|
||||||
final LatLng? coordinate;
|
static const home = '/';
|
||||||
final bool hasTelegramAuth;
|
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() {
|
GoRouter createAppRouter() {
|
||||||
return GoRouter(
|
return GoRouter(
|
||||||
errorBuilder: (context, state) => const MapflowShell(),
|
errorBuilder: (context, state) => const MapflowShell(),
|
||||||
routes: [
|
routes: [
|
||||||
GoRoute(path: '/', builder: (context, state) => const MapflowShell()),
|
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: '/experience/new',
|
path: MapflowRoutes.home,
|
||||||
|
builder: (context, state) => const MapflowShell(),
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: MapflowRoutes.addExperience,
|
||||||
pageBuilder: (context, state) {
|
pageBuilder: (context, state) {
|
||||||
final extra = state.extra;
|
final queryParameters = state.uri.queryParameters;
|
||||||
final args = extra is AddExperienceArgs
|
|
||||||
? extra
|
|
||||||
: const AddExperienceArgs(
|
|
||||||
coordinate: null,
|
|
||||||
hasTelegramAuth: true,
|
|
||||||
);
|
|
||||||
return CustomTransitionPage<void>(
|
return CustomTransitionPage<void>(
|
||||||
fullscreenDialog: true,
|
fullscreenDialog: true,
|
||||||
key: state.pageKey,
|
key: state.pageKey,
|
||||||
child: AddExperienceFlow(
|
child: AddExperienceFlow(
|
||||||
coordinate: args.coordinate,
|
coordinate: _coordinateFromQuery(queryParameters),
|
||||||
hasTelegramAuth: args.hasTelegramAuth,
|
hasTelegramAuth: queryParameters['telegramAuth'] != '0',
|
||||||
),
|
),
|
||||||
transitionsBuilder: (context, animation, _, child) {
|
transitionsBuilder: (context, animation, _, child) {
|
||||||
return SlideTransition(
|
return SlideTransition(
|
||||||
@@ -50,9 +61,28 @@ GoRouter createAppRouter() {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: '/admin/reviews',
|
path: MapflowRoutes.adminReviews,
|
||||||
builder: (context, state) => const AdminVoiceExperiencesScreen(),
|
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);
|
||||||
|
}
|
||||||
|
|||||||
@@ -165,8 +165,7 @@ class _MapContent extends StatelessWidget {
|
|||||||
|
|
||||||
void _openAddFlow(BuildContext context, LatLng? coordinate) {
|
void _openAddFlow(BuildContext context, LatLng? coordinate) {
|
||||||
context.push(
|
context.push(
|
||||||
'/experience/new',
|
MapflowRoutes.addExperienceLocation(
|
||||||
extra: AddExperienceArgs(
|
|
||||||
coordinate: coordinate,
|
coordinate: coordinate,
|
||||||
hasTelegramAuth: state.hasTelegramAuth,
|
hasTelegramAuth: state.hasTelegramAuth,
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user