Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ android {
applicationId 'com.exptech.dpip'
minSdkVersion 26
targetSdkVersion 36
versionCode 300103103
versionCode 300103104
versionName flutterVersionName
multiDexEnabled true
resConfigs "en", "ko", "zh-rTW", "ja", "zh-rCN"
Expand Down
115 changes: 74 additions & 41 deletions lib/app/home/_widgets/forecast_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class _ForecastCardState extends State<ForecastCard> {
final Map<int, GlobalKey> _pageKeys = {};
final Set<int> _measuringPages = {};
List<List<dynamic>> _pages = [];
double maxWeatherWidth = 0;
List<dynamic>? _lastForecast;

@override
void dispose() {
Expand All @@ -34,6 +36,38 @@ class _ForecastCardState extends State<ForecastCard> {
try {
final data = widget.forecast['forecast'] as List<dynamic>?;
if (data == null || data.isEmpty) return const SizedBox.shrink();
if (_lastForecast != data) {
_lastForecast = data;

final List<String> allWeatherTexts = [];
for (final item in data) {
final w = item['weather'] as String?;
if (w != null && w.isNotEmpty) allWeatherTexts.add(w);
}

double longestWidth = 0;
for (final text in allWeatherTexts) {
final tp = TextPainter(
text: TextSpan(
text: text,
style: context.theme.textTheme.bodySmall?.copyWith(
fontWeight: FontWeight.w500,
fontSize: 12,
),
),
maxLines: 1,
textDirection: TextDirection.ltr,
)..layout(minWidth: 0, maxWidth: double.infinity);

longestWidth = max(longestWidth, tp.width);
tp.dispose();
}

const iconWidth = 30;
const spacing = 8;
const popWidth = 55;
maxWeatherWidth = iconWidth + spacing + longestWidth + spacing + popWidth;
}

double minTemp = double.infinity;
double maxTemp = double.negativeInfinity;
Expand All @@ -44,8 +78,8 @@ class _ForecastCardState extends State<ForecastCard> {
}

_pages = <List<dynamic>>[];
for (int i = 0; i < data.length; i += 4) {
_pages.add(data.skip(i).take(4).toList());
for (int i = 0; i < data.length; i += 6) {
_pages.add(data.skip(i).take(6).toList());
}
final pages = _pages;

Expand Down Expand Up @@ -102,7 +136,7 @@ class _ForecastCardState extends State<ForecastCard> {
double height = 0;
final pageData = pages[pageIndex];
for (int i = 0; i < pageData.length; i++) {
final globalIndex = pageIndex * 4 + i;
final globalIndex = pageIndex * 6 + i;
final isExpanded = _expandedItems.contains(globalIndex);
height += isExpanded ? 320 : 84;
if (i < pageData.length - 1 && !isExpanded) height += 1;
Expand All @@ -127,7 +161,7 @@ class _ForecastCardState extends State<ForecastCard> {
setState(() {
_currentPage = index;
if (index < _pages.length) {
final currentPageStart = index * 4;
final currentPageStart = index * 6;
final currentPageEnd = currentPageStart + _pages[index].length - 1;
_expandedItems.removeWhere((expandedIndex) {
return expandedIndex < currentPageStart || expandedIndex > currentPageEnd;
Expand All @@ -136,6 +170,7 @@ class _ForecastCardState extends State<ForecastCard> {
_measuredHeights.clear();
}
}
_measuredHeights.removeWhere((key, value) => key != index);
});
},
itemBuilder: (context, pageIndex) {
Expand Down Expand Up @@ -168,7 +203,7 @@ class _ForecastCardState extends State<ForecastCard> {
child: Column(
mainAxisSize: MainAxisSize.min,
children: pages[pageIndex].asMap().entries.map((entry) {
final globalIndex = pageIndex * 4 + entry.key;
final globalIndex = pageIndex * 6 + entry.key;
return _buildForecastItem(
context,
entry.value as Map<String, dynamic>,
Expand Down Expand Up @@ -232,7 +267,7 @@ class _ForecastCardState extends State<ForecastCard> {
..clear()
..add(index);
}
final pageIndex = index ~/ 4;
final pageIndex = index ~/ 6;
_measuredHeights.remove(pageIndex);
});
},
Expand Down Expand Up @@ -262,7 +297,7 @@ class _ForecastCardState extends State<ForecastCard> {
),
),
SizedBox(
width: 135,
width: maxWeatherWidth,
child: Row(
mainAxisSize: MainAxisSize.min,
spacing: 4,
Expand All @@ -276,45 +311,43 @@ class _ForecastCardState extends State<ForecastCard> {
child: _getWeatherIcon(weather, context),
),
if (weather.isNotEmpty)
Flexible(
child: Text(
weather,
style: context.theme.textTheme.bodySmall?.copyWith(
fontWeight: FontWeight.w500,
color: context.colors.onSurfaceVariant,
fontSize: 12,
),
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
Text(
weather,
style: context.theme.textTheme.bodySmall?.copyWith(
fontWeight: FontWeight.w500,
color: context.colors.onSurfaceVariant,
fontSize: 12,
),
maxLines: 1,
overflow: TextOverflow.visible,
),
if (pop > 0)
Container(
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 2),
decoration: BoxDecoration(
color: Colors.indigo.withValues(alpha: 0.15),
borderRadius: BorderRadius.circular(4),
),
child: Row(
mainAxisSize: MainAxisSize.min,
spacing: 2,
children: [
Icon(
Symbols.rainy_rounded,
size: 13,
Container(
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 2),
decoration: BoxDecoration(
color: Colors.indigo.withValues(alpha: 0.15),
borderRadius: BorderRadius.circular(4),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Symbols.rainy_rounded,
size: 13,
color: Colors.indigo,
),
const SizedBox(width: 2),
Text(
'$pop%',
style: const TextStyle(
fontSize: 11,
color: Colors.indigo,
fontWeight: FontWeight.w700,
),
Text(
'$pop%',
style: TextStyle(
fontSize: 11,
color: Colors.indigo,
fontWeight: FontWeight.w700,
),
),
],
),
),
],
),
),
],
),
),
Expand Down
Loading