buildHistoricalWeatherView function

Widget buildHistoricalWeatherView({
  1. required BuildContext context,
  2. required bool isLoading,
  3. required HourlyWeatherData? historicalWeatherData,
  4. required double latitude,
  5. required double longitude,
  6. String? address,
  7. required String selectedDataType,
  8. required Widget dateRangeSelector,
  9. required void onDataTypeChanged(
    1. String
    ),
})

Build historical weather view.

Implementation

Widget buildHistoricalWeatherView({
  required BuildContext context,
  required bool isLoading,
  required HourlyWeatherData? historicalWeatherData,
  required double latitude,
  required double longitude,
  String? address,
  required String selectedDataType,
  required Widget dateRangeSelector,
  required void Function(String) onDataTypeChanged,
}) {
  if (isLoading) {
    return const Center(child: CircularProgressIndicator());
  }

  if (historicalWeatherData == null) {
    return Center(
      child: Padding(
        padding: const EdgeInsets.all(16),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const Icon(Icons.history, size: 48, color: Colors.grey),
            const SizedBox(height: 16),
            const Text(
              'Tap to load historical weather data',
              style: TextStyle(fontSize: 16),
            ),
            const SizedBox(height: 8),
            Text(
              'Data from 30 days ago (ERA5 archive has 5-7 day delay)',
              style: TextStyle(fontSize: 12, color: Colors.grey[600]),
              textAlign: TextAlign.center,
            ),
          ],
        ),
      ),
    );
  }

  return SingleChildScrollView(
    padding: const EdgeInsets.all(16),
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              'Historical Weather',
              style: Theme.of(context).textTheme.titleLarge,
            ),
            const SizedBox(height: 4),
            Text(
              'Data from ${historicalWeatherData.startDate.year}-${historicalWeatherData.startDate.month.toString().padLeft(2, '0')}-${historicalWeatherData.startDate.day.toString().padLeft(2, '0')} to ${historicalWeatherData.endDate.year}-${historicalWeatherData.endDate.month.toString().padLeft(2, '0')}-${historicalWeatherData.endDate.day.toString().padLeft(2, '0')}',
              style: TextStyle(fontSize: 12, color: Colors.grey[600]),
            ),
          ],
        ),
        const SizedBox(height: 12),
        dateRangeSelector,
        const SizedBox(height: 8),
        if (address != null && address.isNotEmpty) ...[
          Text(address, style: Theme.of(context).textTheme.bodySmall),
          const SizedBox(height: 4),
        ],
        Text(
          'Coordinates: ${latitude.toStringAsFixed(4)}, ${longitude.toStringAsFixed(4)}',
          style: Theme.of(context).textTheme.bodySmall?.copyWith(
            color: Theme.of(
              context,
            ).textTheme.bodySmall?.color?.withValues(alpha: 0.7),
          ),
        ),
        const SizedBox(height: 16),
        buildDataTypeSelector(
          selectedDataType: selectedDataType,
          onSelectionChanged: onDataTypeChanged,
        ),
        const SizedBox(height: 16),
        HourlyWeatherChart(
          data: historicalWeatherData,
          dataType: selectedDataType,
          sortAscending: true, // Historical: oldest to newest
          latitude: latitude,
          longitude: longitude,
          address: address,
          dataSource: 'Historical Weather Data',
        ),
      ],
    ),
  );
}