104 lines
3.6 KiB
Dart
104 lines
3.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import '../../providers/map_provider.dart';
|
|
|
|
class PlaceCard extends ConsumerWidget {
|
|
const PlaceCard({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final selectedPlace =
|
|
ref.watch(mapProvider.select((s) => s.selectedPlace));
|
|
|
|
if (selectedPlace == null) return const SizedBox.shrink();
|
|
|
|
return Positioned(
|
|
left: 0,
|
|
right: 0,
|
|
bottom: 0,
|
|
child: Card(
|
|
margin: const EdgeInsets.all(12),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
selectedPlace.name,
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.close),
|
|
onPressed: () =>
|
|
ref.read(mapProvider.notifier).clearSelectedPlace(),
|
|
iconSize: 20,
|
|
padding: EdgeInsets.zero,
|
|
constraints: const BoxConstraints(),
|
|
),
|
|
],
|
|
),
|
|
if (selectedPlace.address != null) ...[
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
selectedPlace.address!,
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
maxLines: 2,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
],
|
|
if (selectedPlace.category != null) ...[
|
|
const SizedBox(height: 4),
|
|
Chip(
|
|
label: Text(selectedPlace.category!),
|
|
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
|
visualDensity: VisualDensity.compact,
|
|
),
|
|
],
|
|
const SizedBox(height: 12),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: FilledButton.icon(
|
|
onPressed: () {
|
|
context.push('/route', extra: {
|
|
'destLat': selectedPlace.latitude,
|
|
'destLon': selectedPlace.longitude,
|
|
'destName': selectedPlace.name,
|
|
});
|
|
},
|
|
icon: const Icon(Icons.directions),
|
|
label: const Text('Directions'),
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
Expanded(
|
|
child: OutlinedButton.icon(
|
|
onPressed: () {
|
|
if (selectedPlace.osmType != null &&
|
|
selectedPlace.osmId != null) {
|
|
context.push(
|
|
'/place/${selectedPlace.osmType}/${selectedPlace.osmId}',
|
|
);
|
|
}
|
|
},
|
|
icon: const Icon(Icons.bookmark_add_outlined),
|
|
label: const Text('Save'),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|