cofounderella/lib/components/location_dialog.dart

51 lines
1.4 KiB
Dart

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<LocationDialog> createState() => _LocationDialogState();
}
class _LocationDialogState extends State<LocationDialog> {
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'),
),
],
);
}
}