Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
780edd2d3b | ||
|
|
eefb491e87 | ||
|
|
9b2000efc2 | ||
|
|
cc6068b759 | ||
|
|
9a75fb25db | ||
|
|
9b2878f6e3 | ||
|
|
d200cad8be |
@@ -7,6 +7,86 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [1.5.7] - 2026-01-08
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- **Environment widget alignment** - Consistent card heights across all environment widgets
|
||||||
|
- Added `ConstrainedBox(minHeight: 170)` to Weather, Air Quality, and Forecast widgets
|
||||||
|
- All cards now match Sun Position widget height when displaying data
|
||||||
|
|
||||||
|
- **Sun position night labels** - Swap sunrise/sunset labels at night
|
||||||
|
- During day: Sunrise on left, Sunset on right (day arc)
|
||||||
|
- At night: Sunset on left, Sunrise on right (night arc)
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- **Weather widget header** - Changed from location name to "Weather" for consistency
|
||||||
|
- Location now displayed in content area below temperature
|
||||||
|
|
||||||
|
## [1.5.6] - 2026-01-07
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- **Environment user logging** - Now logs API user only once per session instead of on every refresh
|
||||||
|
|
||||||
|
## [1.5.5] - 2026-01-07
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- **Sun position arc overflow** - Arc now constrained to fit within card boundaries
|
||||||
|
- Prevents arc and sun/moon from overflowing on wider displays
|
||||||
|
- Scales radius down when arc height exceeds available space
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- **Debug logging for environment user** - Logs authenticated user on environment data load
|
||||||
|
|
||||||
|
## [1.5.4] - 2026-01-07
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- User display in environment section header (reverted in 1.5.5)
|
||||||
|
|
||||||
|
## [1.5.3] - 2026-01-07
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- **Sun position arc redesign** - Arc now touches horizon at sunrise/sunset points
|
||||||
|
- Arc geometry uses chord-radius calculation for proper horizon intersection
|
||||||
|
- Sunrise/sunset icons integrated at horizon endpoints (no duplicate labels)
|
||||||
|
- Daylight duration centered below arc
|
||||||
|
- Increased card height 20% for better arc visibility (140px → 170px)
|
||||||
|
- **Visual balance improvements** - Sunrise/sunset labels raised 10px, daylight label at bottom
|
||||||
|
|
||||||
|
## [1.5.2] - 2026-01-07
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- **Proportional sun/moon arc visualization** - Arc angle now proportional to day/night duration
|
||||||
|
- Day arc: spans (daylight hours / 24) × 360° above horizon
|
||||||
|
- Night arc: spans (night hours / 24) × 360° with moon traversal
|
||||||
|
- Horizon points represent sunrise/sunset times
|
||||||
|
- Gradient colors: yellow/orange for day, blue/indigo for night
|
||||||
|
- **Sun position widget now updates every 10 minutes** - Position aligned to clock intervals (0/10/20/30/40/50)
|
||||||
|
- Converted to StatefulWidget with timer-based updates
|
||||||
|
- Shows default 7am/5pm sunrise/sunset when API data unavailable (asymmetric for visual effect)
|
||||||
|
- Always displays times and daylight duration (no more "--:--")
|
||||||
|
- **Environment widgets consistent height** - All cards maintain same height in "no data" state
|
||||||
|
|
||||||
|
## [1.5.1] - 2026-01-07
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- **Environment widgets layout redesign** - All 4 widgets always visible with responsive layout
|
||||||
|
- Desktop (>900px): 4-in-a-row with 30/20/20/30 width distribution (Sun | Weather | Air Quality | Forecast)
|
||||||
|
- Tablet (600-900px): 2x2 grid layout
|
||||||
|
- Mobile (<600px): Stacked vertically
|
||||||
|
- Widgets now show "No data available" state instead of being hidden or using mock data
|
||||||
|
- Sun position widget now calculates position from system clock
|
||||||
|
- Defaults to 6am/6pm (12-hour day/night cycles) when API sun times unavailable
|
||||||
|
- Environment data refresh interval changed from 5 minutes to 1 hour
|
||||||
|
|
||||||
## [1.5.0] - 2026-01-06
|
## [1.5.0] - 2026-01-06
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 5.3 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.4 MiB |
@@ -26,6 +26,13 @@ class _DashboardContentState extends ConsumerState<DashboardContent> {
|
|||||||
Timer? _systemStatsTimer;
|
Timer? _systemStatsTimer;
|
||||||
Timer? _environmentTimer;
|
Timer? _environmentTimer;
|
||||||
|
|
||||||
|
/// Tracks if we've logged the environment API user (log once per session)
|
||||||
|
static bool _hasLoggedEnvUser = false;
|
||||||
|
static String? _envApiUser;
|
||||||
|
|
||||||
|
/// Get the environment API user (available after first load)
|
||||||
|
static String? get envApiUser => _envApiUser;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@@ -34,9 +41,9 @@ class _DashboardContentState extends ConsumerState<DashboardContent> {
|
|||||||
const Duration(seconds: 30),
|
const Duration(seconds: 30),
|
||||||
(_) => ref.invalidate(systemStatsProvider),
|
(_) => ref.invalidate(systemStatsProvider),
|
||||||
);
|
);
|
||||||
// Refresh environment data every 5 minutes
|
// Refresh environment data every hour
|
||||||
_environmentTimer = Timer.periodic(
|
_environmentTimer = Timer.periodic(
|
||||||
const Duration(minutes: 5),
|
const Duration(hours: 1),
|
||||||
(_) => ref.invalidate(environmentProvider),
|
(_) => ref.invalidate(environmentProvider),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -129,13 +136,21 @@ class _DashboardContentState extends ConsumerState<DashboardContent> {
|
|||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
|
|
||||||
// Environment - Sun, Weather, Forecast, Air Quality
|
// Environment - Sun, Weather, Forecast, Air Quality
|
||||||
_SectionHeader(title: 'Environment', icon: Icons.eco),
|
const _SectionHeader(title: 'Environment', icon: Icons.eco),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
environmentAsync.when(
|
environmentAsync.when(
|
||||||
data: (envData) => _EnvironmentSection(
|
data: (envData) {
|
||||||
envData: envData,
|
// Store and log user once per session
|
||||||
onRefresh: () => ref.invalidate(environmentProvider),
|
if (!_hasLoggedEnvUser && envData.user != null) {
|
||||||
),
|
_envApiUser = envData.user;
|
||||||
|
_hasLoggedEnvUser = true;
|
||||||
|
debugPrint('Environment API user: ${envData.user}');
|
||||||
|
}
|
||||||
|
return _EnvironmentSection(
|
||||||
|
envData: envData,
|
||||||
|
onRefresh: () => ref.invalidate(environmentProvider),
|
||||||
|
);
|
||||||
|
},
|
||||||
loading: () => const Card(
|
loading: () => const Card(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: EdgeInsets.all(32),
|
padding: EdgeInsets.all(32),
|
||||||
@@ -279,7 +294,12 @@ class _SystemStatsCard extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Environment section displaying sun position, weather, forecast, and air quality.
|
/// Environment section displaying sun position, weather, air quality, and forecast.
|
||||||
|
///
|
||||||
|
/// Layout:
|
||||||
|
/// - Desktop (>900px): 4 widgets in a row - Sun(30%) | Weather(20%) | AirQuality(20%) | Forecast(30%)
|
||||||
|
/// - Tablet (600-900px): 2x2 grid
|
||||||
|
/// - Mobile (<600px): Stacked vertically
|
||||||
class _EnvironmentSection extends StatelessWidget {
|
class _EnvironmentSection extends StatelessWidget {
|
||||||
const _EnvironmentSection({
|
const _EnvironmentSection({
|
||||||
required this.envData,
|
required this.envData,
|
||||||
@@ -293,40 +313,73 @@ class _EnvironmentSection extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return LayoutBuilder(
|
return LayoutBuilder(
|
||||||
builder: (context, constraints) {
|
builder: (context, constraints) {
|
||||||
final isWide = constraints.maxWidth > 600;
|
if (constraints.maxWidth > 900) {
|
||||||
|
// Desktop: 4 in a row (30/20/20/30) - wider widgets on outsides
|
||||||
return Column(
|
return Row(
|
||||||
children: [
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
// Sun Position Widget - prominent at top
|
children: [
|
||||||
SunPositionWidget(sunTimes: envData.sunTimes),
|
Expanded(
|
||||||
const SizedBox(height: 12),
|
flex: 30,
|
||||||
|
child: SunPositionWidget(sunTimes: envData.sunTimes),
|
||||||
// Weather and Forecast side-by-side on wide screens
|
),
|
||||||
if (isWide)
|
const SizedBox(width: 12),
|
||||||
|
Expanded(
|
||||||
|
flex: 20,
|
||||||
|
child: WeatherWidget(apiData: envData.weather),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 12),
|
||||||
|
Expanded(
|
||||||
|
flex: 20,
|
||||||
|
child: AirQualityWidget(apiData: envData.airQuality),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 12),
|
||||||
|
Expanded(
|
||||||
|
flex: 30,
|
||||||
|
child: ForecastWidget(forecast: envData.forecast),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
} else if (constraints.maxWidth > 600) {
|
||||||
|
// Tablet: 2x2 grid
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
Row(
|
Row(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: SunPositionWidget(sunTimes: envData.sunTimes),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 12),
|
||||||
Expanded(child: WeatherWidget(apiData: envData.weather)),
|
Expanded(child: WeatherWidget(apiData: envData.weather)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: AirQualityWidget(apiData: envData.airQuality),
|
||||||
|
),
|
||||||
const SizedBox(width: 12),
|
const SizedBox(width: 12),
|
||||||
Expanded(child: ForecastWidget(forecast: envData.forecast)),
|
Expanded(child: ForecastWidget(forecast: envData.forecast)),
|
||||||
],
|
],
|
||||||
)
|
|
||||||
else
|
|
||||||
Column(
|
|
||||||
children: [
|
|
||||||
WeatherWidget(apiData: envData.weather),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
ForecastWidget(forecast: envData.forecast),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
|
],
|
||||||
// Air Quality - only show if data is available
|
);
|
||||||
if (envData.airQuality != null) ...[
|
} else {
|
||||||
|
// Mobile: stacked vertically
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
SunPositionWidget(sunTimes: envData.sunTimes),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
WeatherWidget(apiData: envData.weather),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
AirQualityWidget(apiData: envData.airQuality),
|
AirQualityWidget(apiData: envData.airQuality),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
ForecastWidget(forecast: envData.forecast),
|
||||||
],
|
],
|
||||||
],
|
);
|
||||||
);
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,10 +28,16 @@ class AirQualityWidget extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final colorScheme = Theme.of(context).colorScheme;
|
final colorScheme = Theme.of(context).colorScheme;
|
||||||
|
|
||||||
|
// Show "no data" state when no API data and no legacy data
|
||||||
|
if (apiData == null && data == null) {
|
||||||
|
if (compact) {
|
||||||
|
return _buildCompactNoData(context, colorScheme);
|
||||||
|
}
|
||||||
|
return _buildNoData(context, colorScheme);
|
||||||
|
}
|
||||||
|
|
||||||
// Convert API data to local model, or use legacy data
|
// Convert API data to local model, or use legacy data
|
||||||
final aqi = apiData != null
|
final aqi = apiData != null ? _fromApiData(apiData!) : data!;
|
||||||
? _fromApiData(apiData!)
|
|
||||||
: (data ?? AirQualityData.mock());
|
|
||||||
|
|
||||||
if (compact) {
|
if (compact) {
|
||||||
return _buildCompact(context, colorScheme, aqi);
|
return _buildCompact(context, colorScheme, aqi);
|
||||||
@@ -61,77 +67,93 @@ class AirQualityWidget extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 8),
|
||||||
|
|
||||||
// AQI Display
|
// Content area with minimum height to match other widgets
|
||||||
Row(
|
ConstrainedBox(
|
||||||
children: [
|
constraints: const BoxConstraints(minHeight: 170),
|
||||||
// AQI number with colored background
|
child: Column(
|
||||||
Container(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
width: 64,
|
mainAxisSize: MainAxisSize.min,
|
||||||
height: 64,
|
children: [
|
||||||
decoration: BoxDecoration(
|
const SizedBox(height: 8),
|
||||||
color: aqi.level.color.withValues(alpha: 0.15),
|
// AQI Display
|
||||||
borderRadius: BorderRadius.circular(12),
|
Row(
|
||||||
border: Border.all(
|
|
||||||
color: aqi.level.color.withValues(alpha: 0.3),
|
|
||||||
width: 2,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: Center(
|
|
||||||
child: Text(
|
|
||||||
'${aqi.index}',
|
|
||||||
style:
|
|
||||||
Theme.of(context).textTheme.headlineMedium?.copyWith(
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: aqi.level.color,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 16),
|
|
||||||
|
|
||||||
// Level info
|
|
||||||
Expanded(
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
children: [
|
||||||
Text(
|
// AQI number with colored background
|
||||||
aqi.level.label,
|
Container(
|
||||||
style:
|
width: 64,
|
||||||
Theme.of(context).textTheme.titleMedium?.copyWith(
|
height: 64,
|
||||||
fontWeight: FontWeight.w600,
|
decoration: BoxDecoration(
|
||||||
|
color: aqi.level.color.withValues(alpha: 0.15),
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
border: Border.all(
|
||||||
|
color: aqi.level.color.withValues(alpha: 0.3),
|
||||||
|
width: 2,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Center(
|
||||||
|
child: Text(
|
||||||
|
'${aqi.index}',
|
||||||
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.headlineMedium
|
||||||
|
?.copyWith(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
color: aqi.level.color,
|
color: aqi.level.color,
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 4),
|
const SizedBox(width: 16),
|
||||||
Text(
|
|
||||||
aqi.level.description,
|
// Level info
|
||||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
Expanded(
|
||||||
color: colorScheme.onSurfaceVariant,
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
aqi.level.label,
|
||||||
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.titleMedium
|
||||||
|
?.copyWith(
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: aqi.level.color,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
maxLines: 2,
|
const SizedBox(height: 4),
|
||||||
overflow: TextOverflow.ellipsis,
|
Text(
|
||||||
|
aqi.level.description,
|
||||||
|
style:
|
||||||
|
Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||||
|
color: colorScheme.onSurfaceVariant,
|
||||||
|
),
|
||||||
|
maxLines: 2,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
|
|
||||||
// Pollutants
|
// Pollutants
|
||||||
if (aqi.pollutants.isNotEmpty) ...[
|
if (aqi.pollutants.isNotEmpty) ...[
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
const Divider(height: 1),
|
const Divider(height: 1),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
Wrap(
|
Wrap(
|
||||||
spacing: 16,
|
spacing: 16,
|
||||||
runSpacing: 8,
|
runSpacing: 8,
|
||||||
children: aqi.pollutants
|
children: aqi.pollutants
|
||||||
.map((p) => _PollutantChip(pollutant: p))
|
.map((p) => _PollutantChip(pollutant: p))
|
||||||
.toList(),
|
.toList(),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
],
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -178,6 +200,97 @@ class AirQualityWidget extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildNoData(BuildContext context, ColorScheme colorScheme) {
|
||||||
|
return Card(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
// Header
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
Icons.air,
|
||||||
|
size: 20,
|
||||||
|
color: colorScheme.onSurfaceVariant,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Text(
|
||||||
|
'Air Quality',
|
||||||
|
style: Theme.of(context).textTheme.titleSmall?.copyWith(
|
||||||
|
color: colorScheme.onSurfaceVariant,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
// Match sun position card height (170px content area)
|
||||||
|
SizedBox(
|
||||||
|
height: 170,
|
||||||
|
child: Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
Icons.air_outlined,
|
||||||
|
size: 32,
|
||||||
|
color: colorScheme.outline,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Text(
|
||||||
|
'No data available',
|
||||||
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||||
|
color: colorScheme.outline,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildCompactNoData(BuildContext context, ColorScheme colorScheme) {
|
||||||
|
return Card(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||||
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
width: 32,
|
||||||
|
height: 32,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: colorScheme.outline.withValues(alpha: 0.15),
|
||||||
|
borderRadius: BorderRadius.circular(6),
|
||||||
|
),
|
||||||
|
child: Center(
|
||||||
|
child: Text(
|
||||||
|
'--',
|
||||||
|
style: Theme.of(context).textTheme.titleSmall?.copyWith(
|
||||||
|
color: colorScheme.outline,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Text(
|
||||||
|
'AQI',
|
||||||
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||||
|
color: colorScheme.outline,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _PollutantChip extends StatelessWidget {
|
class _PollutantChip extends StatelessWidget {
|
||||||
|
|||||||
@@ -27,13 +27,52 @@ class ForecastWidget extends StatelessWidget {
|
|||||||
return Card(
|
return Card(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
child: Center(
|
child: Column(
|
||||||
child: Text(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
'No forecast data available',
|
mainAxisSize: MainAxisSize.min,
|
||||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
children: [
|
||||||
|
// Header
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
Icons.calendar_today,
|
||||||
|
size: 20,
|
||||||
color: colorScheme.onSurfaceVariant,
|
color: colorScheme.onSurfaceVariant,
|
||||||
),
|
),
|
||||||
),
|
const SizedBox(width: 8),
|
||||||
|
Text(
|
||||||
|
'Forecast',
|
||||||
|
style: Theme.of(context).textTheme.titleSmall?.copyWith(
|
||||||
|
color: colorScheme.onSurfaceVariant,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
// Match sun position card height (170px content area)
|
||||||
|
SizedBox(
|
||||||
|
height: 170,
|
||||||
|
child: Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
Icons.event_busy_outlined,
|
||||||
|
size: 32,
|
||||||
|
color: colorScheme.outline,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Text(
|
||||||
|
'No data available',
|
||||||
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||||
|
color: colorScheme.outline,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -67,18 +106,23 @@ class ForecastWidget extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 8),
|
||||||
|
|
||||||
// Forecast days - horizontal scroll
|
// Content area with minimum height to match other widgets
|
||||||
SizedBox(
|
ConstrainedBox(
|
||||||
height: 100,
|
constraints: const BoxConstraints(minHeight: 170),
|
||||||
child: ListView.separated(
|
child: Center(
|
||||||
scrollDirection: Axis.horizontal,
|
child: SizedBox(
|
||||||
itemCount: forecast!.length,
|
height: 110,
|
||||||
separatorBuilder: (_, i) => const SizedBox(width: 12),
|
child: ListView.separated(
|
||||||
itemBuilder: (context, index) {
|
scrollDirection: Axis.horizontal,
|
||||||
return _ForecastDayCard(day: forecast![index]);
|
itemCount: forecast!.length,
|
||||||
},
|
separatorBuilder: (_, i) => const SizedBox(width: 12),
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
return _ForecastDayCard(day: forecast![index]);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import 'dart:async';
|
||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:tatlock_ui/features/front_hall/data/models/environment_model.dart';
|
import 'package:tatlock_ui/features/front_hall/data/models/environment_model.dart';
|
||||||
@@ -9,7 +10,11 @@ import 'package:tatlock_ui/features/front_hall/data/models/environment_model.dar
|
|||||||
/// - Blue tones for night
|
/// - Blue tones for night
|
||||||
/// - Orange tones for sunrise/sunset
|
/// - Orange tones for sunrise/sunset
|
||||||
/// - Yellow tones for daytime
|
/// - Yellow tones for daytime
|
||||||
class SunPositionWidget extends StatelessWidget {
|
///
|
||||||
|
/// Position updates every 10 minutes based on system clock.
|
||||||
|
/// When sun times are unavailable, assumes 12-hour day/night cycles
|
||||||
|
/// (6am sunrise, 6pm sunset).
|
||||||
|
class SunPositionWidget extends StatefulWidget {
|
||||||
const SunPositionWidget({
|
const SunPositionWidget({
|
||||||
super.key,
|
super.key,
|
||||||
this.sunTimes,
|
this.sunTimes,
|
||||||
@@ -22,11 +27,71 @@ class SunPositionWidget extends StatelessWidget {
|
|||||||
/// Whether to use compact layout.
|
/// Whether to use compact layout.
|
||||||
final bool compact;
|
final bool compact;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<SunPositionWidget> createState() => _SunPositionWidgetState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SunPositionWidgetState extends State<SunPositionWidget> {
|
||||||
|
Timer? _positionTimer;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_scheduleNextUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Schedule update at next 10-minute wall clock mark (0/10/20/30/40/50)
|
||||||
|
void _scheduleNextUpdate() {
|
||||||
|
final now = DateTime.now();
|
||||||
|
final currentMinute = now.minute;
|
||||||
|
// Calculate minutes until next 10-minute mark
|
||||||
|
final minutesUntilNext = 10 - (currentMinute % 10);
|
||||||
|
final secondsUntilNext = (minutesUntilNext * 60) - now.second;
|
||||||
|
|
||||||
|
_positionTimer = Timer(
|
||||||
|
Duration(seconds: secondsUntilNext),
|
||||||
|
() {
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {});
|
||||||
|
_scheduleNextUpdate();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_positionTimer?.cancel();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get sunrise time, defaulting to 7am if not available (asymmetric for visual effect)
|
||||||
|
DateTime get _sunrise {
|
||||||
|
final now = DateTime.now();
|
||||||
|
return widget.sunTimes?.sunrise ?? DateTime(now.year, now.month, now.day, 7, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get sunset time, defaulting to 5pm if not available (asymmetric for visual effect)
|
||||||
|
DateTime get _sunset {
|
||||||
|
final now = DateTime.now();
|
||||||
|
return widget.sunTimes?.sunset ?? DateTime(now.year, now.month, now.day, 17, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Calculate daylight minutes from sunrise/sunset
|
||||||
|
int get _daylightMinutes {
|
||||||
|
return _sunset.difference(_sunrise).inMinutes;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool get _isDaytime {
|
||||||
|
final now = DateTime.now();
|
||||||
|
return now.isAfter(_sunrise) && now.isBefore(_sunset);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final colorScheme = Theme.of(context).colorScheme;
|
final colorScheme = Theme.of(context).colorScheme;
|
||||||
|
|
||||||
if (compact) {
|
if (widget.compact) {
|
||||||
return _buildCompact(context, colorScheme);
|
return _buildCompact(context, colorScheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,42 +119,65 @@ class SunPositionWidget extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 8),
|
||||||
|
|
||||||
// Arc visualization
|
// Arc with integrated horizon labels
|
||||||
|
// At night: sunset on left (night start), sunrise on right (night end)
|
||||||
|
// During day: sunrise on left (day start), sunset on right (day end)
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: 120,
|
height: 170,
|
||||||
child: CustomPaint(
|
child: LayoutBuilder(
|
||||||
size: const Size(double.infinity, 120),
|
builder: (context, constraints) {
|
||||||
painter: _SunArcPainter(
|
return Stack(
|
||||||
sunTimes: sunTimes,
|
clipBehavior: Clip.none,
|
||||||
isDark: colorScheme.brightness == Brightness.dark,
|
children: [
|
||||||
),
|
// Arc painter
|
||||||
|
Positioned.fill(
|
||||||
|
child: CustomPaint(
|
||||||
|
painter: _SunArcPainter(
|
||||||
|
sunTimes: widget.sunTimes,
|
||||||
|
isDark: colorScheme.brightness == Brightness.dark,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
// Left horizon: Sunrise during day, Sunset at night
|
||||||
|
Positioned(
|
||||||
|
left: 0,
|
||||||
|
bottom: 10,
|
||||||
|
child: _HorizonTimeDisplay(
|
||||||
|
icon: _isDaytime ? Icons.wb_twilight : Icons.nights_stay,
|
||||||
|
label: _isDaytime ? 'Sunrise' : 'Sunset',
|
||||||
|
time: _isDaytime ? _sunrise : _sunset,
|
||||||
|
iconColor: _isDaytime ? Colors.orange : Colors.deepOrange,
|
||||||
|
alignment: CrossAxisAlignment.start,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
// Daylight display centered (at bottom for balance)
|
||||||
|
Positioned(
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
bottom: 0,
|
||||||
|
child: Center(
|
||||||
|
child: _DaylightDisplay(minutes: _daylightMinutes),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
// Right horizon: Sunset during day, Sunrise at night
|
||||||
|
Positioned(
|
||||||
|
right: 0,
|
||||||
|
bottom: 10,
|
||||||
|
child: _HorizonTimeDisplay(
|
||||||
|
icon: _isDaytime ? Icons.nights_stay : Icons.wb_twilight,
|
||||||
|
label: _isDaytime ? 'Sunset' : 'Sunrise',
|
||||||
|
time: _isDaytime ? _sunset : _sunrise,
|
||||||
|
iconColor: _isDaytime ? Colors.deepOrange : Colors.orange,
|
||||||
|
alignment: CrossAxisAlignment.end,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
|
|
||||||
// Sunrise/Sunset times
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
_TimeDisplay(
|
|
||||||
icon: Icons.wb_twilight,
|
|
||||||
label: 'Sunrise',
|
|
||||||
time: sunTimes?.sunrise,
|
|
||||||
iconColor: Colors.orange,
|
|
||||||
),
|
|
||||||
if (sunTimes?.daylightMinutes != null)
|
|
||||||
_DaylightDisplay(minutes: sunTimes!.daylightMinutes!),
|
|
||||||
_TimeDisplay(
|
|
||||||
icon: Icons.nights_stay,
|
|
||||||
label: 'Sunset',
|
|
||||||
time: sunTimes?.sunset,
|
|
||||||
iconColor: Colors.deepOrange,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -114,11 +202,11 @@ class SunPositionWidget extends StatelessWidget {
|
|||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
_formatTime(sunTimes?.sunrise),
|
_formatTime(_sunrise),
|
||||||
style: Theme.of(context).textTheme.labelSmall,
|
style: Theme.of(context).textTheme.labelSmall,
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
_formatTime(sunTimes?.sunset),
|
_formatTime(_sunset),
|
||||||
style: Theme.of(context).textTheme.labelSmall,
|
style: Theme.of(context).textTheme.labelSmall,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -129,46 +217,44 @@ class SunPositionWidget extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool get _isDaytime {
|
String _formatTime(DateTime time) {
|
||||||
if (sunTimes?.sunrise == null || sunTimes?.sunset == null) return true;
|
|
||||||
final now = DateTime.now();
|
|
||||||
return now.isAfter(sunTimes!.sunrise!) && now.isBefore(sunTimes!.sunset!);
|
|
||||||
}
|
|
||||||
|
|
||||||
String _formatTime(DateTime? time) {
|
|
||||||
if (time == null) return '--:--';
|
|
||||||
return '${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}';
|
return '${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _TimeDisplay extends StatelessWidget {
|
/// Horizon-aligned time display with icon above time and label.
|
||||||
const _TimeDisplay({
|
class _HorizonTimeDisplay extends StatelessWidget {
|
||||||
|
const _HorizonTimeDisplay({
|
||||||
required this.icon,
|
required this.icon,
|
||||||
required this.label,
|
required this.label,
|
||||||
required this.time,
|
required this.time,
|
||||||
this.iconColor,
|
this.iconColor,
|
||||||
|
this.alignment = CrossAxisAlignment.center,
|
||||||
});
|
});
|
||||||
|
|
||||||
final IconData icon;
|
final IconData icon;
|
||||||
final String label;
|
final String label;
|
||||||
final DateTime? time;
|
final DateTime time;
|
||||||
final Color? iconColor;
|
final Color? iconColor;
|
||||||
|
final CrossAxisAlignment alignment;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final colorScheme = Theme.of(context).colorScheme;
|
final colorScheme = Theme.of(context).colorScheme;
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: alignment,
|
||||||
children: [
|
children: [
|
||||||
Icon(
|
Icon(
|
||||||
icon,
|
icon,
|
||||||
size: 20,
|
size: 18,
|
||||||
color: iconColor ?? colorScheme.primary,
|
color: iconColor ?? colorScheme.primary,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 4),
|
const SizedBox(height: 2),
|
||||||
Text(
|
Text(
|
||||||
_formatTime(time),
|
'${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}',
|
||||||
style: Theme.of(context).textTheme.titleSmall?.copyWith(
|
style: Theme.of(context).textTheme.labelMedium?.copyWith(
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -176,16 +262,12 @@ class _TimeDisplay extends StatelessWidget {
|
|||||||
label,
|
label,
|
||||||
style: Theme.of(context).textTheme.labelSmall?.copyWith(
|
style: Theme.of(context).textTheme.labelSmall?.copyWith(
|
||||||
color: colorScheme.onSurfaceVariant,
|
color: colorScheme.onSurfaceVariant,
|
||||||
|
fontSize: 10,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
String _formatTime(DateTime? time) {
|
|
||||||
if (time == null) return '--:--';
|
|
||||||
return '${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class _DaylightDisplay extends StatelessWidget {
|
class _DaylightDisplay extends StatelessWidget {
|
||||||
@@ -224,6 +306,11 @@ class _DaylightDisplay extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Custom painter for the sun arc visualization.
|
/// Custom painter for the sun arc visualization.
|
||||||
|
///
|
||||||
|
/// The arc is proportional to the day/night duration:
|
||||||
|
/// - During day: shows a day arc spanning (daylight hours / 24) × 360°
|
||||||
|
/// - During night: shows a night arc spanning (night hours / 24) × 360°
|
||||||
|
/// - Arc endpoints touch the horizon line at sunrise/sunset positions
|
||||||
class _SunArcPainter extends CustomPainter {
|
class _SunArcPainter extends CustomPainter {
|
||||||
_SunArcPainter({
|
_SunArcPainter({
|
||||||
this.sunTimes,
|
this.sunTimes,
|
||||||
@@ -241,200 +328,273 @@ class _SunArcPainter extends CustomPainter {
|
|||||||
static const _dayGold = Color(0xFFffb300);
|
static const _dayGold = Color(0xFFffb300);
|
||||||
static const _duskOrange = Color(0xFFef6c00);
|
static const _duskOrange = Color(0xFFef6c00);
|
||||||
static const _nightIndigo = Color(0xFF283593);
|
static const _nightIndigo = Color(0xFF283593);
|
||||||
|
static const _moonSilver = Color(0xFFB0BEC5);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void paint(Canvas canvas, Size size) {
|
void paint(Canvas canvas, Size size) {
|
||||||
final center = Offset(size.width / 2, size.height - 10);
|
final now = DateTime.now();
|
||||||
final radius = math.min(size.width / 2 - 20, size.height - 30);
|
|
||||||
|
// Get sunrise/sunset times (default to 7am/5pm for asymmetric visual)
|
||||||
|
final sunrise = sunTimes?.sunrise ?? DateTime(now.year, now.month, now.day, 7, 0);
|
||||||
|
final sunset = sunTimes?.sunset ?? DateTime(now.year, now.month, now.day, 17, 0);
|
||||||
|
|
||||||
|
// Calculate durations
|
||||||
|
final daylightMinutes = sunset.difference(sunrise).inMinutes;
|
||||||
|
final nightMinutes = 1440 - daylightMinutes; // 24 hours = 1440 minutes
|
||||||
|
|
||||||
|
// Determine if currently day or night
|
||||||
|
final isDaytime = now.isAfter(sunrise) && now.isBefore(sunset);
|
||||||
|
|
||||||
|
// Calculate arc angles (proportional to duration)
|
||||||
|
final dayArcAngle = (daylightMinutes / 1440) * 2 * math.pi;
|
||||||
|
final nightArcAngle = (nightMinutes / 1440) * 2 * math.pi;
|
||||||
|
|
||||||
|
// Layout constants - horizon is 50px from bottom to leave room for labels
|
||||||
|
const horizonY = 50.0;
|
||||||
|
const horizontalPadding = 40.0;
|
||||||
|
final horizonWidth = size.width - (horizontalPadding * 2);
|
||||||
|
final centerX = size.width / 2;
|
||||||
|
|
||||||
// Draw horizon line
|
// Draw horizon line
|
||||||
final horizonPaint = Paint()
|
final horizonPaint = Paint()
|
||||||
..color = isDark ? Colors.white24 : Colors.black12
|
..color = isDark ? Colors.white24 : Colors.black12
|
||||||
..strokeWidth = 1;
|
..strokeWidth = 1;
|
||||||
canvas.drawLine(
|
canvas.drawLine(
|
||||||
Offset(center.dx - radius - 10, center.dy),
|
Offset(horizontalPadding - 5, size.height - horizonY),
|
||||||
Offset(center.dx + radius + 10, center.dy),
|
Offset(size.width - horizontalPadding + 5, size.height - horizonY),
|
||||||
horizonPaint,
|
horizonPaint,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create gradient for arc background
|
if (isDaytime) {
|
||||||
|
_drawDayArc(canvas, size, centerX, horizonWidth, horizonY, dayArcAngle, now, sunrise, sunset);
|
||||||
|
} else {
|
||||||
|
_drawNightArc(canvas, size, centerX, horizonWidth, horizonY, nightArcAngle, now, sunrise, sunset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _drawDayArc(
|
||||||
|
Canvas canvas,
|
||||||
|
Size size,
|
||||||
|
double centerX,
|
||||||
|
double horizonWidth,
|
||||||
|
double horizonY,
|
||||||
|
double arcAngle,
|
||||||
|
DateTime now,
|
||||||
|
DateTime sunrise,
|
||||||
|
DateTime sunset,
|
||||||
|
) {
|
||||||
|
// Clamp arc angle between 30° and 180° for visual sanity
|
||||||
|
final clampedAngle = arcAngle.clamp(math.pi / 6, math.pi);
|
||||||
|
|
||||||
|
// Calculate radius so arc endpoints touch horizon
|
||||||
|
// For a chord of width W and arc angle θ: R = W / (2 * sin(θ/2))
|
||||||
|
var radius = horizonWidth / (2 * math.sin(clampedAngle / 2));
|
||||||
|
|
||||||
|
// Constrain arc height to fit within available space (leave 25px margin for sun)
|
||||||
|
final maxArcHeight = size.height - horizonY - 25;
|
||||||
|
final arcHeight = radius * (1 - math.cos(clampedAngle / 2));
|
||||||
|
if (arcHeight > maxArcHeight) {
|
||||||
|
// Scale radius down to fit
|
||||||
|
radius = maxArcHeight / (1 - math.cos(clampedAngle / 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Arc center is below the horizon for an upward-bulging arc
|
||||||
|
// Distance from chord to center = R * cos(θ/2)
|
||||||
|
final horizonYPos = size.height - horizonY;
|
||||||
|
final centerY = horizonYPos + radius * math.cos(clampedAngle / 2);
|
||||||
|
final center = Offset(centerX, centerY);
|
||||||
|
|
||||||
|
// The arc starts at the LEFT horizon point
|
||||||
|
// In canvas coords (Y down), angle to left point = 3π/2 - θ/2
|
||||||
|
// The arc sweeps clockwise (positive) through angle θ to reach right point
|
||||||
|
final startAngle = (3 * math.pi / 2) - (clampedAngle / 2);
|
||||||
|
|
||||||
final arcRect = Rect.fromCenter(
|
final arcRect = Rect.fromCenter(
|
||||||
center: center,
|
center: center,
|
||||||
width: radius * 2,
|
width: radius * 2,
|
||||||
height: radius * 2,
|
height: radius * 2,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Draw arc background (night portion below horizon implied)
|
// Draw arc background with day gradient
|
||||||
final arcBgPaint = Paint()
|
final arcPaint = Paint()
|
||||||
..style = PaintingStyle.stroke
|
..style = PaintingStyle.stroke
|
||||||
..strokeWidth = 8
|
..strokeWidth = 6
|
||||||
..strokeCap = StrokeCap.round;
|
..strokeCap = StrokeCap.round
|
||||||
|
..shader = SweepGradient(
|
||||||
|
center: Alignment.center,
|
||||||
|
startAngle: 0,
|
||||||
|
endAngle: 2 * math.pi,
|
||||||
|
colors: [
|
||||||
|
_dawnOrange.withValues(alpha: 0.6),
|
||||||
|
_sunriseOrange.withValues(alpha: 0.7),
|
||||||
|
_dayYellow.withValues(alpha: 0.8),
|
||||||
|
_dayGold.withValues(alpha: 0.8),
|
||||||
|
_dayYellow.withValues(alpha: 0.7),
|
||||||
|
_duskOrange.withValues(alpha: 0.6),
|
||||||
|
],
|
||||||
|
stops: const [0.0, 0.15, 0.4, 0.6, 0.85, 1.0],
|
||||||
|
transform: GradientRotation(startAngle),
|
||||||
|
).createShader(arcRect);
|
||||||
|
|
||||||
// Create gradient that transitions through time of day colors
|
// Draw the arc (positive sweep = clockwise in canvas coords = visually upward arc)
|
||||||
arcBgPaint.shader = SweepGradient(
|
canvas.drawArc(arcRect, startAngle, clampedAngle, false, arcPaint);
|
||||||
center: Alignment.bottomCenter,
|
|
||||||
startAngle: math.pi,
|
|
||||||
endAngle: 2 * math.pi,
|
|
||||||
colors: [
|
|
||||||
_nightBlue.withValues(alpha: 0.3),
|
|
||||||
_dawnOrange.withValues(alpha: 0.5),
|
|
||||||
_sunriseOrange.withValues(alpha: 0.6),
|
|
||||||
_dayYellow.withValues(alpha: 0.7),
|
|
||||||
_dayGold.withValues(alpha: 0.7),
|
|
||||||
_dayYellow.withValues(alpha: 0.6),
|
|
||||||
_duskOrange.withValues(alpha: 0.5),
|
|
||||||
_nightIndigo.withValues(alpha: 0.3),
|
|
||||||
],
|
|
||||||
stops: const [0.0, 0.1, 0.2, 0.4, 0.5, 0.6, 0.8, 1.0],
|
|
||||||
transform: const GradientRotation(-math.pi / 2),
|
|
||||||
).createShader(arcRect);
|
|
||||||
|
|
||||||
// Draw the arc (semicircle from left to right)
|
// Calculate sun position along the arc
|
||||||
canvas.drawArc(
|
|
||||||
arcRect,
|
|
||||||
math.pi, // Start at left (180 degrees)
|
|
||||||
math.pi, // Sweep 180 degrees (semicircle)
|
|
||||||
false,
|
|
||||||
arcBgPaint,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Calculate sun position
|
|
||||||
final sunPosition = _calculateSunPosition();
|
|
||||||
|
|
||||||
// Draw sun/moon indicator
|
|
||||||
final angle = math.pi + (sunPosition * math.pi); // Map 0-1 to pi-2pi
|
|
||||||
final sunX = center.dx + radius * math.cos(angle);
|
|
||||||
final sunY = center.dy + radius * math.sin(angle);
|
|
||||||
|
|
||||||
// Determine if day or night for icon/color
|
|
||||||
final isDaytime = sunPosition > 0 && sunPosition < 1;
|
|
||||||
final isNearHorizon = sunPosition < 0.15 || sunPosition > 0.85;
|
|
||||||
|
|
||||||
// Sun/moon glow
|
|
||||||
if (isDaytime) {
|
|
||||||
final glowColor = isNearHorizon ? _dawnOrange : _dayYellow;
|
|
||||||
final glowPaint = Paint()
|
|
||||||
..shader = RadialGradient(
|
|
||||||
colors: [
|
|
||||||
glowColor.withValues(alpha: 0.6),
|
|
||||||
glowColor.withValues(alpha: 0.0),
|
|
||||||
],
|
|
||||||
).createShader(
|
|
||||||
Rect.fromCircle(center: Offset(sunX, sunY), radius: 24),
|
|
||||||
);
|
|
||||||
canvas.drawCircle(Offset(sunX, sunY), 24, glowPaint);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sun/moon circle
|
|
||||||
final sunPaint = Paint()
|
|
||||||
..style = PaintingStyle.fill
|
|
||||||
..color = isDaytime
|
|
||||||
? (isNearHorizon ? _sunriseOrange : _dayYellow)
|
|
||||||
: _nightIndigo;
|
|
||||||
|
|
||||||
canvas.drawCircle(Offset(sunX, sunY), 12, sunPaint);
|
|
||||||
|
|
||||||
// Sun rays or moon craters
|
|
||||||
if (isDaytime) {
|
|
||||||
final rayPaint = Paint()
|
|
||||||
..style = PaintingStyle.stroke
|
|
||||||
..strokeWidth = 2
|
|
||||||
..color = (isNearHorizon ? _dawnOrange : _dayGold).withValues(alpha: 0.8);
|
|
||||||
|
|
||||||
for (var i = 0; i < 8; i++) {
|
|
||||||
final rayAngle = (i * math.pi / 4);
|
|
||||||
final innerRadius = 14.0;
|
|
||||||
final outerRadius = 18.0;
|
|
||||||
canvas.drawLine(
|
|
||||||
Offset(
|
|
||||||
sunX + innerRadius * math.cos(rayAngle),
|
|
||||||
sunY + innerRadius * math.sin(rayAngle),
|
|
||||||
),
|
|
||||||
Offset(
|
|
||||||
sunX + outerRadius * math.cos(rayAngle),
|
|
||||||
sunY + outerRadius * math.sin(rayAngle),
|
|
||||||
),
|
|
||||||
rayPaint,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Moon highlight
|
|
||||||
final moonHighlight = Paint()
|
|
||||||
..style = PaintingStyle.fill
|
|
||||||
..color = Colors.white24;
|
|
||||||
canvas.drawCircle(Offset(sunX - 3, sunY - 3), 4, moonHighlight);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw time markers on arc
|
|
||||||
_drawTimeMarkers(canvas, center, radius);
|
|
||||||
}
|
|
||||||
|
|
||||||
double _calculateSunPosition() {
|
|
||||||
if (sunTimes?.sunrise == null || sunTimes?.sunset == null) {
|
|
||||||
// Default to noon position
|
|
||||||
return 0.5;
|
|
||||||
}
|
|
||||||
|
|
||||||
final now = DateTime.now();
|
|
||||||
final sunrise = sunTimes!.sunrise!;
|
|
||||||
final sunset = sunTimes!.sunset!;
|
|
||||||
|
|
||||||
// Before sunrise
|
|
||||||
if (now.isBefore(sunrise)) {
|
|
||||||
// Calculate position in pre-dawn (negative values = below horizon)
|
|
||||||
final midnight = DateTime(now.year, now.month, now.day);
|
|
||||||
final minutesSinceMidnight = now.difference(midnight).inMinutes;
|
|
||||||
final minutesToSunrise = sunrise.difference(midnight).inMinutes;
|
|
||||||
// Map to 0 at sunrise, negative before
|
|
||||||
return (minutesSinceMidnight / minutesToSunrise) * 0.15 - 0.1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// After sunset
|
|
||||||
if (now.isAfter(sunset)) {
|
|
||||||
// Calculate position in post-dusk
|
|
||||||
final minutesSinceSunset = now.difference(sunset).inMinutes;
|
|
||||||
final nextMidnight = DateTime(now.year, now.month, now.day + 1);
|
|
||||||
final minutesToMidnight = nextMidnight.difference(sunset).inMinutes;
|
|
||||||
// Map to 1 at sunset, going towards negative
|
|
||||||
return 1.0 + (minutesSinceSunset / minutesToMidnight) * 0.1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// During daylight hours
|
|
||||||
final totalDaylight = sunset.difference(sunrise).inMinutes;
|
final totalDaylight = sunset.difference(sunrise).inMinutes;
|
||||||
final minutesSinceSunrise = now.difference(sunrise).inMinutes;
|
final minutesSinceSunrise = now.difference(sunrise).inMinutes;
|
||||||
return minutesSinceSunrise / totalDaylight;
|
final progress = (minutesSinceSunrise / totalDaylight).clamp(0.0, 1.0);
|
||||||
}
|
|
||||||
|
|
||||||
void _drawTimeMarkers(Canvas canvas, Offset center, double radius) {
|
// Map progress to angle along the arc (0 = sunrise/left, 1 = sunset/right)
|
||||||
final textPainter = TextPainter(
|
final sunAngle = startAngle + (progress * clampedAngle);
|
||||||
textDirection: TextDirection.ltr,
|
final sunX = center.dx + radius * math.cos(sunAngle);
|
||||||
textAlign: TextAlign.center,
|
final sunY = center.dy + radius * math.sin(sunAngle);
|
||||||
);
|
|
||||||
|
|
||||||
final markerStyle = TextStyle(
|
// Determine sun color based on position (orange near horizon, yellow at peak)
|
||||||
fontSize: 10,
|
final isNearHorizon = progress < 0.15 || progress > 0.85;
|
||||||
color: isDark ? Colors.white38 : Colors.black38,
|
final sunColor = isNearHorizon ? _sunriseOrange : _dayYellow;
|
||||||
);
|
final glowColor = isNearHorizon ? _dawnOrange : _dayYellow;
|
||||||
|
|
||||||
// Draw quarter markers (6am, 12pm, 6pm positions conceptually)
|
// Draw sun glow
|
||||||
final markers = ['6:00', '12:00', '18:00'];
|
final glowPaint = Paint()
|
||||||
final positions = [0.25, 0.5, 0.75];
|
..shader = RadialGradient(
|
||||||
|
colors: [
|
||||||
|
glowColor.withValues(alpha: 0.6),
|
||||||
|
glowColor.withValues(alpha: 0.0),
|
||||||
|
],
|
||||||
|
).createShader(Rect.fromCircle(center: Offset(sunX, sunY), radius: 20));
|
||||||
|
canvas.drawCircle(Offset(sunX, sunY), 20, glowPaint);
|
||||||
|
|
||||||
for (var i = 0; i < markers.length; i++) {
|
// Draw sun
|
||||||
final angle = math.pi + (positions[i] * math.pi);
|
final sunPaint = Paint()
|
||||||
final markerRadius = radius + 15;
|
..style = PaintingStyle.fill
|
||||||
final x = center.dx + markerRadius * math.cos(angle);
|
..color = sunColor;
|
||||||
final y = center.dy + markerRadius * math.sin(angle);
|
canvas.drawCircle(Offset(sunX, sunY), 10, sunPaint);
|
||||||
|
|
||||||
textPainter.text = TextSpan(text: markers[i], style: markerStyle);
|
// Draw sun rays
|
||||||
textPainter.layout();
|
final rayPaint = Paint()
|
||||||
textPainter.paint(
|
..style = PaintingStyle.stroke
|
||||||
canvas,
|
..strokeWidth = 2
|
||||||
Offset(x - textPainter.width / 2, y - textPainter.height / 2),
|
..color = (isNearHorizon ? _dawnOrange : _dayGold).withValues(alpha: 0.8);
|
||||||
|
|
||||||
|
for (var i = 0; i < 8; i++) {
|
||||||
|
final rayAngle = (i * math.pi / 4);
|
||||||
|
canvas.drawLine(
|
||||||
|
Offset(sunX + 12 * math.cos(rayAngle), sunY + 12 * math.sin(rayAngle)),
|
||||||
|
Offset(sunX + 16 * math.cos(rayAngle), sunY + 16 * math.sin(rayAngle)),
|
||||||
|
rayPaint,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _drawNightArc(
|
||||||
|
Canvas canvas,
|
||||||
|
Size size,
|
||||||
|
double centerX,
|
||||||
|
double horizonWidth,
|
||||||
|
double horizonY,
|
||||||
|
double arcAngle,
|
||||||
|
DateTime now,
|
||||||
|
DateTime sunrise,
|
||||||
|
DateTime sunset,
|
||||||
|
) {
|
||||||
|
// Clamp arc angle between 30° and 180° for visual sanity
|
||||||
|
final clampedAngle = arcAngle.clamp(math.pi / 6, math.pi);
|
||||||
|
|
||||||
|
// Calculate radius so arc endpoints touch horizon
|
||||||
|
var radius = horizonWidth / (2 * math.sin(clampedAngle / 2));
|
||||||
|
|
||||||
|
// Constrain arc height to fit within available space (leave 20px margin for moon)
|
||||||
|
final maxArcHeight = size.height - horizonY - 20;
|
||||||
|
final arcHeight = radius * (1 - math.cos(clampedAngle / 2));
|
||||||
|
if (arcHeight > maxArcHeight) {
|
||||||
|
// Scale radius down to fit
|
||||||
|
radius = maxArcHeight / (1 - math.cos(clampedAngle / 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Arc center is below the horizon for an upward-bulging arc
|
||||||
|
final horizonYPos = size.height - horizonY;
|
||||||
|
final centerY = horizonYPos + radius * math.cos(clampedAngle / 2);
|
||||||
|
final center = Offset(centerX, centerY);
|
||||||
|
|
||||||
|
// The arc starts at the LEFT horizon point
|
||||||
|
// In canvas coords (Y down), angle to left point = 3π/2 - θ/2
|
||||||
|
final startAngle = (3 * math.pi / 2) - (clampedAngle / 2);
|
||||||
|
|
||||||
|
final arcRect = Rect.fromCenter(
|
||||||
|
center: center,
|
||||||
|
width: radius * 2,
|
||||||
|
height: radius * 2,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Draw arc background with night gradient
|
||||||
|
final arcPaint = Paint()
|
||||||
|
..style = PaintingStyle.stroke
|
||||||
|
..strokeWidth = 6
|
||||||
|
..strokeCap = StrokeCap.round
|
||||||
|
..shader = SweepGradient(
|
||||||
|
center: Alignment.center,
|
||||||
|
startAngle: 0,
|
||||||
|
endAngle: 2 * math.pi,
|
||||||
|
colors: [
|
||||||
|
_duskOrange.withValues(alpha: 0.4),
|
||||||
|
_nightIndigo.withValues(alpha: 0.5),
|
||||||
|
_nightBlue.withValues(alpha: 0.6),
|
||||||
|
_nightBlue.withValues(alpha: 0.6),
|
||||||
|
_nightIndigo.withValues(alpha: 0.5),
|
||||||
|
_dawnOrange.withValues(alpha: 0.4),
|
||||||
|
],
|
||||||
|
stops: const [0.0, 0.15, 0.4, 0.6, 0.85, 1.0],
|
||||||
|
transform: GradientRotation(startAngle),
|
||||||
|
).createShader(arcRect);
|
||||||
|
|
||||||
|
// Draw the arc (positive sweep = clockwise in canvas coords)
|
||||||
|
canvas.drawArc(arcRect, startAngle, clampedAngle, false, arcPaint);
|
||||||
|
|
||||||
|
// Calculate moon position
|
||||||
|
// Night spans from sunset to next sunrise
|
||||||
|
final double progress;
|
||||||
|
if (now.isAfter(sunset)) {
|
||||||
|
// After sunset: progress from sunset toward midnight and beyond
|
||||||
|
final nextSunrise = DateTime(now.year, now.month, now.day + 1, sunrise.hour, sunrise.minute);
|
||||||
|
final nightDuration = nextSunrise.difference(sunset).inMinutes;
|
||||||
|
final minutesSinceSunset = now.difference(sunset).inMinutes;
|
||||||
|
progress = (minutesSinceSunset / nightDuration).clamp(0.0, 1.0);
|
||||||
|
} else {
|
||||||
|
// Before sunrise: progress toward sunrise
|
||||||
|
final prevSunset = DateTime(now.year, now.month, now.day - 1, sunset.hour, sunset.minute);
|
||||||
|
final nightDuration = sunrise.difference(prevSunset).inMinutes;
|
||||||
|
final minutesSincePrevSunset = now.difference(prevSunset).inMinutes;
|
||||||
|
progress = (minutesSincePrevSunset / nightDuration).clamp(0.0, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Map progress to angle along the arc (0 = sunset/left, 1 = sunrise/right)
|
||||||
|
final moonAngle = startAngle + (progress * clampedAngle);
|
||||||
|
final moonX = center.dx + radius * math.cos(moonAngle);
|
||||||
|
final moonY = center.dy + radius * math.sin(moonAngle);
|
||||||
|
|
||||||
|
// Draw moon glow
|
||||||
|
final glowPaint = Paint()
|
||||||
|
..shader = RadialGradient(
|
||||||
|
colors: [
|
||||||
|
_moonSilver.withValues(alpha: 0.3),
|
||||||
|
_moonSilver.withValues(alpha: 0.0),
|
||||||
|
],
|
||||||
|
).createShader(Rect.fromCircle(center: Offset(moonX, moonY), radius: 16));
|
||||||
|
canvas.drawCircle(Offset(moonX, moonY), 16, glowPaint);
|
||||||
|
|
||||||
|
// Draw moon
|
||||||
|
final moonPaint = Paint()
|
||||||
|
..style = PaintingStyle.fill
|
||||||
|
..color = _moonSilver;
|
||||||
|
canvas.drawCircle(Offset(moonX, moonY), 8, moonPaint);
|
||||||
|
|
||||||
|
// Draw crescent shadow for moon effect
|
||||||
|
final shadowPaint = Paint()
|
||||||
|
..style = PaintingStyle.fill
|
||||||
|
..color = _nightBlue.withValues(alpha: 0.7);
|
||||||
|
canvas.drawCircle(Offset(moonX + 3, moonY - 1), 6, shadowPaint);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool shouldRepaint(covariant _SunArcPainter oldDelegate) {
|
bool shouldRepaint(covariant _SunArcPainter oldDelegate) {
|
||||||
return oldDelegate.sunTimes != sunTimes || oldDelegate.isDark != isDark;
|
return oldDelegate.sunTimes != sunTimes || oldDelegate.isDark != isDark;
|
||||||
|
|||||||
@@ -26,10 +26,16 @@ class WeatherWidget extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final colorScheme = Theme.of(context).colorScheme;
|
final colorScheme = Theme.of(context).colorScheme;
|
||||||
|
|
||||||
|
// Show "no data" state when no API data and no legacy data
|
||||||
|
if (apiData == null && data == null) {
|
||||||
|
if (compact) {
|
||||||
|
return _buildCompactNoData(context, colorScheme);
|
||||||
|
}
|
||||||
|
return _buildNoData(context, colorScheme);
|
||||||
|
}
|
||||||
|
|
||||||
// Convert API data to local model, or use legacy data
|
// Convert API data to local model, or use legacy data
|
||||||
final weather = apiData != null
|
final weather = apiData != null ? _fromApiData(apiData!) : data!;
|
||||||
? _fromApiData(apiData!)
|
|
||||||
: (data ?? WeatherData.mock());
|
|
||||||
|
|
||||||
if (compact) {
|
if (compact) {
|
||||||
return _buildCompact(context, colorScheme, weather);
|
return _buildCompact(context, colorScheme, weather);
|
||||||
@@ -53,7 +59,7 @@ class WeatherWidget extends StatelessWidget {
|
|||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Text(
|
child: Text(
|
||||||
weather.location,
|
'Weather',
|
||||||
style: Theme.of(context).textTheme.titleSmall?.copyWith(
|
style: Theme.of(context).textTheme.titleSmall?.copyWith(
|
||||||
color: colorScheme.onSurfaceVariant,
|
color: colorScheme.onSurfaceVariant,
|
||||||
),
|
),
|
||||||
@@ -63,89 +69,119 @@ class WeatherWidget extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 8),
|
||||||
|
|
||||||
// Main weather display (matching AQI layout)
|
// Content area with minimum height to match other widgets
|
||||||
Row(
|
ConstrainedBox(
|
||||||
children: [
|
constraints: const BoxConstraints(minHeight: 170),
|
||||||
// Weather icon in box (like AQI number box)
|
child: Column(
|
||||||
Container(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
width: 64,
|
mainAxisSize: MainAxisSize.min,
|
||||||
height: 64,
|
children: [
|
||||||
decoration: BoxDecoration(
|
const SizedBox(height: 8),
|
||||||
color: (weather.iconColor ?? colorScheme.primary)
|
// Main weather display (matching AQI layout)
|
||||||
.withValues(alpha: 0.15),
|
Row(
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
border: Border.all(
|
|
||||||
color: (weather.iconColor ?? colorScheme.primary)
|
|
||||||
.withValues(alpha: 0.3),
|
|
||||||
width: 2,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: Center(
|
|
||||||
child: Icon(
|
|
||||||
weather.icon,
|
|
||||||
size: 32,
|
|
||||||
color: weather.iconColor ?? colorScheme.primary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 16),
|
|
||||||
|
|
||||||
// Temperature and condition
|
|
||||||
Expanded(
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
children: [
|
||||||
Text(
|
// Weather icon in box (like AQI number box)
|
||||||
'${weather.temperature.round()}°${weather.unit.symbol}',
|
Container(
|
||||||
style:
|
width: 64,
|
||||||
Theme.of(context).textTheme.titleMedium?.copyWith(
|
height: 64,
|
||||||
fontWeight: FontWeight.w600,
|
decoration: BoxDecoration(
|
||||||
),
|
color: (weather.iconColor ?? colorScheme.primary)
|
||||||
|
.withValues(alpha: 0.15),
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
border: Border.all(
|
||||||
|
color: (weather.iconColor ?? colorScheme.primary)
|
||||||
|
.withValues(alpha: 0.3),
|
||||||
|
width: 2,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Center(
|
||||||
|
child: Icon(
|
||||||
|
weather.icon,
|
||||||
|
size: 32,
|
||||||
|
color: weather.iconColor ?? colorScheme.primary,
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 4),
|
const SizedBox(width: 16),
|
||||||
Text(
|
|
||||||
weather.condition,
|
// Temperature and condition
|
||||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
Expanded(
|
||||||
color: colorScheme.onSurfaceVariant,
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
'${weather.temperature.round()}°${weather.unit.symbol}',
|
||||||
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.titleMedium
|
||||||
|
?.copyWith(
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
maxLines: 2,
|
const SizedBox(height: 4),
|
||||||
overflow: TextOverflow.ellipsis,
|
Text(
|
||||||
|
weather.condition,
|
||||||
|
style:
|
||||||
|
Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||||
|
color: colorScheme.onSurfaceVariant,
|
||||||
|
),
|
||||||
|
maxLines: 2,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
if (weather.location.isNotEmpty) ...[
|
||||||
|
const SizedBox(height: 2),
|
||||||
|
Text(
|
||||||
|
weather.location,
|
||||||
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.labelSmall
|
||||||
|
?.copyWith(
|
||||||
|
color: colorScheme.outline,
|
||||||
|
),
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
|
|
||||||
// Details
|
// Details
|
||||||
if (weather.humidity != null || weather.windSpeed != null) ...[
|
if (weather.humidity != null || weather.windSpeed != null) ...[
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
const Divider(height: 1),
|
const Divider(height: 1),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
Wrap(
|
Wrap(
|
||||||
spacing: 16,
|
spacing: 16,
|
||||||
runSpacing: 8,
|
runSpacing: 8,
|
||||||
children: [
|
children: [
|
||||||
if (weather.humidity != null)
|
if (weather.humidity != null)
|
||||||
_DetailChip(
|
_DetailChip(
|
||||||
label: 'Humidity',
|
label: 'Humidity',
|
||||||
value: '${weather.humidity}%',
|
value: '${weather.humidity}%',
|
||||||
),
|
),
|
||||||
if (weather.windSpeed != null)
|
if (weather.windSpeed != null)
|
||||||
_DetailChip(
|
_DetailChip(
|
||||||
label: 'Wind',
|
label: 'Wind',
|
||||||
value: '${weather.windSpeed!.round()} ${weather.windUnit}',
|
value:
|
||||||
),
|
'${weather.windSpeed!.round()} ${weather.windUnit}',
|
||||||
if (weather.feelsLike != null)
|
),
|
||||||
_DetailChip(
|
if (weather.feelsLike != null)
|
||||||
label: 'Feels',
|
_DetailChip(
|
||||||
value: '${weather.feelsLike!.round()}°${weather.unit.symbol}',
|
label: 'Feels',
|
||||||
|
value:
|
||||||
|
'${weather.feelsLike!.round()}°${weather.unit.symbol}',
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
|
],
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -180,6 +216,86 @@ class WeatherWidget extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildNoData(BuildContext context, ColorScheme colorScheme) {
|
||||||
|
return Card(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
// Header
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
Icons.wb_sunny_outlined,
|
||||||
|
size: 20,
|
||||||
|
color: colorScheme.onSurfaceVariant,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Text(
|
||||||
|
'Weather',
|
||||||
|
style: Theme.of(context).textTheme.titleSmall?.copyWith(
|
||||||
|
color: colorScheme.onSurfaceVariant,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
// Match sun position card height (170px content area)
|
||||||
|
SizedBox(
|
||||||
|
height: 170,
|
||||||
|
child: Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
Icons.cloud_off_outlined,
|
||||||
|
size: 32,
|
||||||
|
color: colorScheme.outline,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Text(
|
||||||
|
'No data available',
|
||||||
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||||
|
color: colorScheme.outline,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildCompactNoData(BuildContext context, ColorScheme colorScheme) {
|
||||||
|
return Card(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||||
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
Icons.cloud_off_outlined,
|
||||||
|
size: 24,
|
||||||
|
color: colorScheme.outline,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Text(
|
||||||
|
'--',
|
||||||
|
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||||
|
color: colorScheme.outline,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _DetailChip extends StatelessWidget {
|
class _DetailChip extends StatelessWidget {
|
||||||
|
|||||||
+1
-1
@@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
|||||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||||
# In Windows, build-name is used as the major, minor, and patch parts
|
# In Windows, build-name is used as the major, minor, and patch parts
|
||||||
# of the product and file versions while build-number is used as the build suffix.
|
# of the product and file versions while build-number is used as the build suffix.
|
||||||
version: 1.5.0+1
|
version: 1.5.7+1
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.10.4
|
sdk: ^3.10.4
|
||||||
|
|||||||
@@ -89,7 +89,8 @@ void main() {
|
|||||||
expect(find.text('Air Quality'), findsOneWidget);
|
expect(find.text('Air Quality'), findsOneWidget);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('hides Air Quality widget when no data', (tester) async {
|
testWidgets('shows Air Quality widget with no data state when data unavailable',
|
||||||
|
(tester) async {
|
||||||
await setLargeWindowSize(tester);
|
await setLargeWindowSize(tester);
|
||||||
harness.givenAuthenticatedUser();
|
harness.givenAuthenticatedUser();
|
||||||
harness.givenQuickLinks();
|
harness.givenQuickLinks();
|
||||||
@@ -99,8 +100,9 @@ void main() {
|
|||||||
await tester.pumpWidget(harness.wrap(const FrontHallPage()));
|
await tester.pumpWidget(harness.wrap(const FrontHallPage()));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
// Air Quality widget should not be present
|
// Air Quality widget should still be present, showing "no data" state
|
||||||
expect(find.byType(AirQualityWidget), findsNothing);
|
expect(find.byType(AirQualityWidget), findsOneWidget);
|
||||||
|
expect(find.text('Air Quality'), findsOneWidget);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('calls environment API on mount', (tester) async {
|
testWidgets('calls environment API on mount', (tester) async {
|
||||||
|
|||||||
Reference in New Issue
Block a user