import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'dart:math'; // Returns a localized wind speed label (e.g., "calm", "gale") based on km/h value. String getWindSpeedType(double windSpeed) { final levels = >[ [1, 'calm'], [5, 'light_air'], [11, 'light_breeze'], [19, 'gentle_breeze'], [28, 'moderate_breeze'], [38, 'fresh_breeze'], [49, 'strong_breeze'], [61, 'high_wind'], [74, 'gale'], [88, 'strong_gale'], [102, 'storm'], [117, 'violent_storm'], ]; for (final level in levels) { if (windSpeed < (level[0] as num)) return (level[1] as String).tr(); } return 'hurricane'.tr(); } // Build SVG string representing UV index severity String buildUVSvg(Color colorSurface, uvValue) { final hexColorSurface = '#${colorSurface.value.toRadixString(16).padLeft(8, '0').substring(2)}'; // Convert Flutter Color to hex string (e.g., #RRGGBB) for SVG fill. String returnSvg = ''; if (uvValue >= 0 && uvValue <= 3) { returnSvg = ''' '''; } else if (uvValue > 3 && uvValue <= 6) { returnSvg = ''' '''; } else if (uvValue > 6 && uvValue <= 8) { returnSvg = ''' '''; } else if (uvValue > 8 && uvValue <= 10) { returnSvg = ''' '''; } else if (uvValue > 10) { returnSvg = ''' '''; } return returnSvg; } // Convert wind direction in degrees to compass label (e.g., N, SE) String getCompassDirection(int degrees) { var directions = [ 'wind_dir_n'.tr(), 'wind_dir_ne'.tr(), 'wind_dir_e'.tr(), 'wind_dir_se'.tr(), 'wind_dir_s'.tr(), 'wind_dir_sw'.tr(), 'wind_dir_w'.tr(), 'wind_dir_nw'.tr() ]; int index = ((degrees + 22.5) ~/ 45) % 8; return directions[index]; } // Build pressure‐level SVG based on the given pressure reading (hPa) String buildPressueSvg( Color colorPrimary, Color colorHigh, Color colorSurface, pressueValue) { final hexColorPrimary = '#${colorPrimary.value.toRadixString(16).padLeft(8, '0').substring(2)}'; final hexColorHigh = '#${colorHigh.value.toRadixString(16).padLeft(8, '0').substring(2)}'; final hexColorSurface = '#${colorSurface.value.toRadixString(16).padLeft(8, '0').substring(2)}'; String returnSvg = ''; if (pressueValue < 980) { returnSvg = ''' '''; } else if (pressueValue > 980 && pressueValue <= 1005) { returnSvg = ''' '''; } else if (pressueValue > 1005 && pressueValue <= 1020) { returnSvg = ''' '''; } else if (pressueValue > 1020 && pressueValue <= 1035) { returnSvg = ''' '''; } else if (pressueValue > 1036) { returnSvg = ''' '''; } return returnSvg; } // Build visibility SVG String buildVisibilitySvg(Color color) { final hexColor = '#${color.value.toRadixString(16).padLeft(8, '0').substring(2)}'; return ''' '''; } // Build Wind SVG String buildWindSvg(Color color, Color colorSurface) { final hexColor = '#${color.value.toRadixString(16).padLeft(8, '0').substring(2)}'; final hexColorSurface = '#${colorSurface.value.toRadixString(16).padLeft(8, '0').substring(2)}'; return ''' '''; } // Returns SVG to visualize humidity level based on percentage String buildHumidity(Color color, int humidityValue) { final hexColor = '#${color.value.toRadixString(16).padLeft(8, '0').substring(2)}'; String returnSvg = ''; if (humidityValue < 30) { returnSvg = ''' '; '''; } else if (humidityValue >= 30 && humidityValue < 50) { returnSvg = ''' '; '''; } else if (humidityValue >= 50 && humidityValue < 70) { returnSvg = ''' '; '''; } else if (humidityValue >= 70 && humidityValue < 90) { returnSvg = ''' '; '''; } else if (humidityValue >= 90) { returnSvg = ''' '; '''; } return returnSvg; } // Build cloud svg String buildCloudCoverSvg(Color color) { final hexColor = '#${color.value.toRadixString(16).padLeft(8, '0').substring(2)}'; return ''' '''; } // Return SVG representing the sun's path from sunrise to sunset String buildSunPathWithIcon({ required Color pathColor, required double percent, required Color outLineColor, bool showSun = true, }) { final hexColor = '#${pathColor.value.toRadixString(16).padLeft(8, '0').substring(2)}'; final hexColoroutLine = '#${outLineColor.value.toRadixString(16).padLeft(8, '0').substring(2)}'; const svgWidth = 176.0; final shift = -0.0; final stretch = 1.0; final t = ((percent + shift) * stretch).clamp(0.0, 1.0); final sunX = t * svgWidth; final sunY = 70 - 70 * sin(pi * t); final sunYEndStart = 60 - 70 * sin(pi * t); return ''' '''; } // Convert UV index value to a localized risk category string String getUvIndexType(int uvIndex) { if (uvIndex >= 0 && uvIndex <= 3) { return "low_forecast_uv".tr(); } else if (uvIndex > 3 && uvIndex <= 6) { return "moderate_forecast_uv".tr(); } else if (uvIndex > 6 && uvIndex <= 8) { return "high_forecast_uv".tr(); } else if (uvIndex > 8 && uvIndex <= 10) { return "very_high_forecast_uv".tr(); } else if (uvIndex > 10) { return "extreme_forecast_uv".tr(); } else { return "error"; } } String buildNowHourSvg(Color colorPrimary) { final hexColorPrimary = '#${colorPrimary.value.toRadixString(16).padLeft(8, '0').substring(2)}'; String returnSvg = ''; returnSvg = ''' '''; return returnSvg; } // Moon path String buildMoonPathWithIcon({ required Color pathColor, required double percent, required Color outLineColor, bool showMoon = true, int moonIllumination = 100, }) { final hexColor = '#${pathColor.value.toRadixString(16).padLeft(8, '0').substring(2)}'; final hexColoroutLine = '#${outLineColor.value.toRadixString(16).padLeft(8, '0').substring(2)}'; const svgWidth = 176.0; final shift = -0.0; final stretch = 1.0; final t = ((percent + shift) * stretch).clamp(0.0, 1.0); final moonX = t * svgWidth; final moonY = 70 - 70 * sin(pi * t); final moonYEndStart = 60 - 70 * sin(pi * t); final moonFill = showMoon ? 'radialGradient(circle at center, white ${moonIllumination}%, transparent 100%)' : 'transparent'; return ''' '''; } bool isFoldableLayout(BuildContext context) { return MediaQuery.of(context).size.width > 840; }