buildCurrentWeatherView function

Widget buildCurrentWeatherView({
  1. required BuildContext context,
  2. required WeatherData weatherData,
  3. required double latitude,
  4. required double longitude,
  5. String? address,
  6. required bool showDailyPrecipitation,
  7. required VoidCallback onTogglePrecipitation,
})

Build current weather view.

Implementation

Widget buildCurrentWeatherView({
  required BuildContext context,
  required WeatherData weatherData,
  required double latitude,
  required double longitude,
  String? address,
  required bool showDailyPrecipitation,
  required VoidCallback onTogglePrecipitation,
}) {
  final timeFormat = DateFormat('yyyy-MM-dd HH:mm');

  return SingleChildScrollView(
    padding: const EdgeInsets.all(16),
    child: Column(
      mainAxisSize: MainAxisSize.min,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        // Location.
        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: 12),

        // Main weather display.
        Center(
          child: Column(
            children: [
              Text(
                weatherData.weatherIcon,
                style: const TextStyle(fontSize: 60),
              ),
              const SizedBox(height: 6),
              Text(
                weatherData.weatherDescription,
                style: Theme.of(context).textTheme.titleLarge,
              ),
              const SizedBox(height: 2),
              Text(
                '${weatherData.temperature.toStringAsFixed(1)}°C',
                style: Theme.of(context).textTheme.displayMedium?.copyWith(
                  fontWeight: FontWeight.bold,
                ),
              ),

              // Show today's high/low if available.
              if (weatherData.dailyMaxTemp != null &&
                  weatherData.dailyMinTemp != null) ...[
                const SizedBox(height: 4),
                Text(
                  'L: ${weatherData.dailyMinTemp!.toStringAsFixed(1)}° H: ${weatherData.dailyMaxTemp!.toStringAsFixed(1)}°',
                  style: Theme.of(
                    context,
                  ).textTheme.titleMedium?.copyWith(color: Colors.grey[600]),
                ),
              ],
            ],
          ),
        ),
        const SizedBox(height: 16),

        // Weather details.
        buildWeatherDetail(
          icon: Icons.water_drop,
          label: 'Humidity',
          value: '${weatherData.humidity}%',
        ),
        buildWeatherDetail(
          icon: Icons.air,
          label: 'Wind Speed',
          value: '${weatherData.windSpeed.toStringAsFixed(1)} km/h',
        ),
        buildWindDirectionDetail(weatherData),
        buildPrecipitationDetail(
          weather: weatherData,
          showDailyPrecipitation: showDailyPrecipitation,
          onToggle: onTogglePrecipitation,
        ),
        const SizedBox(height: 12),
        Center(
          child: Text(
            'Updated: ${timeFormat.format(weatherData.time)} UTC',
            style: Theme.of(
              context,
            ).textTheme.bodySmall?.copyWith(color: Colors.grey),
          ),
        ),
      ],
    ),
  );
}