import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:geolocator/geolocator.dart';

class DashboardScreen extends StatefulWidget {
  const DashboardScreen({super.key});

  @override
  _DashboardScreenState createState() => _DashboardScreenState();
}

class _DashboardScreenState extends State<DashboardScreen> {
  LatLng _initialPosition = const LatLng(25.7617, 80.1918); // Example position
  late Position _currentPosition;

  @override
  void initState() {
    super.initState();
    _getUserLocation();
  }

  _getUserLocation() async {
    _currentPosition = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
    setState(() {
      _initialPosition = LatLng(_currentPosition.latitude, _currentPosition.longitude);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
          title: const Center(
            child: Text('Delivery Dashboard'),
          )
      ),
      body: GoogleMap(
        initialCameraPosition: CameraPosition(
          target: _initialPosition,
          zoom: 10.0,
        ),
        onMapCreated: (controller) {
        },
        markers: {
          Marker(
            markerId: const MarkerId('currentPosition'),
            position: _initialPosition,
            infoWindow: const InfoWindow(title: 'Current Position'),
          ),
          // Add additional markers for delivery locations
        },
        polylines: {
          Polyline(
            polylineId: const PolylineId('route'),
            points: [_initialPosition, const LatLng(37.80483, -122.47242)], // Add the points of your route here
            color: Colors.blue,
            width: 5,
          ),
        },
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          // Add your action for button here
        },
        child: const Icon(Icons.navigation),
      ),
    );
  }
}
