import 'package:flutter/material.dart'; import '../models/location.dart'; import 'location_selector.dart'; /// Custom dialog widget for LocationSelector class LocationDialog extends StatefulWidget { final Function(MyLocation) onLocationSelected; const LocationDialog({super.key, required this.onLocationSelected}); @override State createState() => _LocationDialogState(); } class _LocationDialogState extends State { MyLocation? _selectedLocation; @override Widget build(BuildContext context) { return AlertDialog( title: const Text('Select Location'), content: LocationSelector( onLocationChanged: (location) { // Update selectedLocation when location changes setState(() { _selectedLocation = location; }); }, ), actions: [ TextButton( onPressed: () { Navigator.of(context).pop(); // Close dialog on cancel }, child: const Text('Cancel'), ), ElevatedButton( onPressed: _selectedLocation != null ? () { // Pass the selected location to caller and close dialog widget.onLocationSelected(_selectedLocation!); Navigator.of(context).pop(); } : null, // Disable button when _selectedLocation is null child: const Text('Apply'), ), ], ); } }