buildPrecipitationDetail function

Widget buildPrecipitationDetail({
  1. required WeatherData weather,
  2. required bool showDailyPrecipitation,
  3. required VoidCallback onToggle,
})

Build precipitation detail with hourly/daily toggle.

Implementation

Widget buildPrecipitationDetail({
  required WeatherData weather,
  required bool showDailyPrecipitation,
  required VoidCallback onToggle,
}) {
  // API returns precipitation for the past hour (mm)
  // User can toggle to see today's accumulated total.
  final precipValue = showDailyPrecipitation
      ? (weather.todayTotalPrecipitation ??
            weather.precipitation) // Today's total accumulated
      : weather.precipitation; // Past hour
  final unit = showDailyPrecipitation ? 'mm' : 'mm';

  return InkWell(
    onTap: onToggle,
    child: Padding(
      padding: const EdgeInsets.symmetric(vertical: 6),
      child: Row(
        children: [
          Icon(Icons.umbrella, size: 24, color: Colors.grey[600]),
          const SizedBox(width: 16),
          Expanded(
            child: Row(
              children: [
                Text(
                  showDailyPrecipitation
                      ? 'Precipitation (Today Total)'
                      : 'Precipitation (Past Hour)',
                  style: const TextStyle(fontSize: 15),
                ),
                const SizedBox(width: 8),
                Icon(Icons.swap_horiz, size: 16, color: Colors.grey[400]),
              ],
            ),
          ),
          Text(
            '${precipValue.toStringAsFixed(1)} $unit',
            style: const TextStyle(fontSize: 15, fontWeight: FontWeight.w600),
          ),
        ],
      ),
    ),
  );
}