-
Notifications
You must be signed in to change notification settings - Fork 48
[Mobile] Add "Share air quality" from location detail sheet #3657
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d77614c
Revert "Investigate mobile session expiry and add auth diagnostics"
8225860
Add first pass of air quality sharing
d13e0a6
Add share options for air quality updates
585785f
Polish share card text layout
4068106
Remove auth investigation and simulator workaround from share PR
6b72813
Merge staging into mobile-share-air-quality
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
300 changes: 300 additions & 0 deletions
300
src/mobile/lib/src/app/dashboard/widgets/air_quality_share_card.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,300 @@ | ||
| import 'dart:convert'; | ||
|
|
||
| import 'package:airqo/src/app/dashboard/models/airquality_response.dart'; | ||
| import 'package:airqo/src/meta/utils/colors.dart'; | ||
| import 'package:flutter/material.dart'; | ||
|
|
||
| class AirQualityShareCard extends StatelessWidget { | ||
| final Measurement measurement; | ||
| final String? fallbackLocationName; | ||
|
|
||
| const AirQualityShareCard({ | ||
| super.key, | ||
| required this.measurement, | ||
| this.fallbackLocationName, | ||
| }); | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| final locationName = _sanitizeText( | ||
| measurement.siteDetails?.searchName ?? | ||
| measurement.siteDetails?.name ?? | ||
| fallbackLocationName ?? | ||
| 'AirQo location', | ||
| ); | ||
| final locationDescription = _sanitizeText( | ||
| _getLocationDescription(measurement), | ||
| ); | ||
| final category = _categoryLabel( | ||
| _sanitizeText(measurement.aqiCategory ?? 'Unavailable'), | ||
| ); | ||
| final pm25Value = measurement.pm25?.value; | ||
| final healthTip = _sanitizeText( | ||
| measurement.healthTips?.firstOrNull?.tagLine ?? | ||
| measurement.healthTips?.firstOrNull?.description ?? | ||
| 'Stay informed and plan your outdoor time wisely.', | ||
| ); | ||
| final categoryColor = _getAqiColor(measurement); | ||
| final isDark = Theme.of(context).brightness == Brightness.dark; | ||
| final cardTextColor = isDark ? Colors.white : const Color(0xFF122033); | ||
| final secondaryTextColor = cardTextColor.withValues(alpha: 0.72); | ||
| final titleFontSize = _titleFontSize(locationName); | ||
| final categoryFontSize = _categoryFontSize(category); | ||
|
|
||
| return Container( | ||
| width: double.infinity, | ||
| padding: const EdgeInsets.all(20), | ||
| decoration: BoxDecoration( | ||
| borderRadius: BorderRadius.circular(28), | ||
| gradient: LinearGradient( | ||
| begin: Alignment.topLeft, | ||
| end: Alignment.bottomRight, | ||
| colors: [ | ||
| categoryColor.withValues(alpha: isDark ? 0.75 : 0.92), | ||
| AppColors.primaryColor, | ||
| isDark ? const Color(0xFF111827) : const Color(0xFFF4F8FF), | ||
| ], | ||
| stops: const [0.0, 0.58, 1.0], | ||
| ), | ||
| boxShadow: [ | ||
| BoxShadow( | ||
| color: categoryColor.withValues(alpha: 0.22), | ||
| blurRadius: 28, | ||
| offset: const Offset(0, 14), | ||
| ), | ||
| ], | ||
| ), | ||
| child: Column( | ||
| crossAxisAlignment: CrossAxisAlignment.start, | ||
| mainAxisSize: MainAxisSize.min, | ||
| children: [ | ||
| Row( | ||
| crossAxisAlignment: CrossAxisAlignment.start, | ||
| children: [ | ||
| Expanded( | ||
| child: Column( | ||
| crossAxisAlignment: CrossAxisAlignment.start, | ||
| children: [ | ||
| Text( | ||
| 'AirQo', | ||
| style: TextStyle( | ||
| color: cardTextColor.withValues(alpha: 0.88), | ||
| fontSize: 16, | ||
| fontWeight: FontWeight.w700, | ||
| letterSpacing: 0.2, | ||
| ), | ||
| ), | ||
| const SizedBox(height: 10), | ||
| Text( | ||
| locationName, | ||
| maxLines: 2, | ||
| overflow: TextOverflow.ellipsis, | ||
| style: TextStyle( | ||
| color: cardTextColor, | ||
| fontSize: titleFontSize, | ||
| height: 1.02, | ||
| fontWeight: FontWeight.w800, | ||
| ), | ||
| ), | ||
| if (locationDescription.isNotEmpty) ...[ | ||
| const SizedBox(height: 8), | ||
| Text( | ||
| locationDescription, | ||
| maxLines: 2, | ||
| overflow: TextOverflow.ellipsis, | ||
| style: TextStyle( | ||
| color: secondaryTextColor, | ||
| fontSize: 13, | ||
| height: 1.25, | ||
| fontWeight: FontWeight.w500, | ||
| ), | ||
| ), | ||
| ], | ||
| ], | ||
| ), | ||
| ), | ||
| const SizedBox(width: 12), | ||
| ConstrainedBox( | ||
| constraints: const BoxConstraints(maxWidth: 124), | ||
| child: Container( | ||
| padding: const EdgeInsets.symmetric( | ||
| horizontal: 12, | ||
| vertical: 8, | ||
| ), | ||
| decoration: BoxDecoration( | ||
| color: Colors.white.withValues(alpha: isDark ? 0.12 : 0.84), | ||
| borderRadius: BorderRadius.circular(999), | ||
| ), | ||
| child: Center( | ||
| child: Text( | ||
| category, | ||
| maxLines: 1, | ||
| textAlign: TextAlign.center, | ||
| overflow: TextOverflow.ellipsis, | ||
| style: TextStyle( | ||
| color: isDark ? Colors.white : categoryColor, | ||
| fontSize: categoryFontSize, | ||
| height: 1.0, | ||
| fontWeight: FontWeight.w700, | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| ], | ||
| ), | ||
| const SizedBox(height: 20), | ||
| Row( | ||
| crossAxisAlignment: CrossAxisAlignment.end, | ||
| children: [ | ||
| Flexible( | ||
| child: FittedBox( | ||
| fit: BoxFit.scaleDown, | ||
| alignment: Alignment.bottomLeft, | ||
| child: Text( | ||
| pm25Value?.toStringAsFixed(1) ?? '--', | ||
| style: TextStyle( | ||
| color: cardTextColor, | ||
| fontSize: 72, | ||
| height: 0.92, | ||
| fontWeight: FontWeight.w800, | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| const SizedBox(width: 8), | ||
| Padding( | ||
| padding: const EdgeInsets.only(bottom: 8), | ||
| child: Text( | ||
| 'PM2.5 µg/m³', | ||
| style: TextStyle( | ||
| color: secondaryTextColor, | ||
| fontSize: 14, | ||
| fontWeight: FontWeight.w600, | ||
| ), | ||
| ), | ||
| ), | ||
| ], | ||
| ), | ||
| const SizedBox(height: 16), | ||
| Container( | ||
| width: double.infinity, | ||
| padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12), | ||
| decoration: BoxDecoration( | ||
| color: Colors.white.withValues(alpha: isDark ? 0.08 : 0.82), | ||
| borderRadius: BorderRadius.circular(18), | ||
| ), | ||
| child: Text( | ||
| healthTip, | ||
| maxLines: 3, | ||
| overflow: TextOverflow.ellipsis, | ||
| style: TextStyle( | ||
| color: cardTextColor, | ||
| fontSize: 14, | ||
| height: 1.3, | ||
| fontWeight: FontWeight.w600, | ||
| ), | ||
| ), | ||
| ), | ||
| const SizedBox(height: 16), | ||
| Text( | ||
| 'Shared from the AirQo app', | ||
| style: TextStyle( | ||
| color: secondaryTextColor, | ||
| fontSize: 12, | ||
| fontWeight: FontWeight.w600, | ||
| ), | ||
| ), | ||
| ], | ||
| ), | ||
| ); | ||
| } | ||
|
|
||
| String _getLocationDescription(Measurement measurement) { | ||
| final siteDetails = measurement.siteDetails; | ||
| if (siteDetails == null) return ''; | ||
|
|
||
| final parts = <String>[]; | ||
|
|
||
| if (siteDetails.city != null && siteDetails.city!.isNotEmpty) { | ||
| parts.add(siteDetails.city!); | ||
| } else if (siteDetails.town != null && siteDetails.town!.isNotEmpty) { | ||
| parts.add(siteDetails.town!); | ||
| } | ||
|
|
||
| if (siteDetails.region != null && siteDetails.region!.isNotEmpty) { | ||
| parts.add(siteDetails.region!); | ||
| } else if (siteDetails.county != null && siteDetails.county!.isNotEmpty) { | ||
| parts.add(siteDetails.county!); | ||
| } | ||
|
|
||
| if (siteDetails.country != null && siteDetails.country!.isNotEmpty) { | ||
| parts.add(siteDetails.country!); | ||
| } | ||
|
|
||
| return parts.join(', '); | ||
| } | ||
|
|
||
| Color _getAqiColor(Measurement measurement) { | ||
| if (measurement.aqiColor != null) { | ||
| try { | ||
| final colorString = measurement.aqiColor!.replaceAll('#', ''); | ||
| return Color(int.parse('0xFF$colorString')); | ||
| } catch (_) {} | ||
| } | ||
|
|
||
| switch (measurement.aqiCategory?.toLowerCase() ?? '') { | ||
| case 'good': | ||
| return const Color(0xFF179D5B); | ||
| case 'moderate': | ||
| return const Color(0xFFC79000); | ||
| case 'unhealthy for sensitive groups': | ||
| case 'u4sg': | ||
| return const Color(0xFFE17827); | ||
| case 'unhealthy': | ||
| return const Color(0xFFD63A45); | ||
| case 'very unhealthy': | ||
| return const Color(0xFF7540B5); | ||
| case 'hazardous': | ||
| return const Color(0xFF6D4C41); | ||
| default: | ||
| return AppColors.primaryColor; | ||
| } | ||
| } | ||
|
|
||
| double _titleFontSize(String title) { | ||
| if (title.length <= 12) return 30; | ||
| if (title.length <= 20) return 27; | ||
| if (title.length <= 28) return 24; | ||
| return 22; | ||
| } | ||
|
|
||
| double _categoryFontSize(String category) { | ||
| if (category.length <= 10) return 12; | ||
| if (category.length <= 16) return 11; | ||
| return 10; | ||
| } | ||
|
|
||
| String _categoryLabel(String category) { | ||
| switch (category.toLowerCase()) { | ||
| case 'unhealthy for sensitive groups': | ||
| return 'Sensitive Groups'; | ||
| case 'very unhealthy': | ||
| return 'Very Unhealthy'; | ||
| default: | ||
| return category; | ||
| } | ||
| } | ||
|
|
||
| String _sanitizeText(String value) { | ||
| if (!value.contains('Ã') && !value.contains('Â') && !value.contains('â')) { | ||
| return value; | ||
| } | ||
|
|
||
| try { | ||
| return utf8.decode(latin1.encode(value)); | ||
| } catch (_) { | ||
| return value; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.