Skip to content
Open
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
45 changes: 45 additions & 0 deletions .github/workflows/flutter_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Flutter Build

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '17'

- uses: subosito/flutter-action@v2
with:
flutter-version: '3.19.0'
channel: 'stable'

- name: Install dependencies
run: flutter pub get

- name: Verify formatting
run: dart format --output=none --set-exit-if-changed .

- name: Analyze project source
run: flutter analyze

- name: Run tests
run: flutter test

- name: Build APK
run: flutter build apk --release

- name: Upload APK
uses: actions/upload-artifact@v4
with:
name: release-apk
path: build/app/outputs/flutter-apk/app-release.apk
18 changes: 15 additions & 3 deletions lib/screens/forecast_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ class _ForecastPageState extends State<ForecastPage> {
final now = DateTime.now();
// Filter hours after now
_hourlyForecast = hours.where((h) {
final t = DateTime.parse(h['time']); // 2024-01-01 00:00
final t = DateTime.tryParse(h['time']); // 2024-01-01 00:00
if (t == null) return false;
return t.isAfter(now);
}).take(12).map<Map<String, dynamic>>((hour) => {
'time': hour['time'].split(' ')[1],
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After filtering out hours where DateTime.tryParse returns null, the code directly accesses hour['time'].split(' ')[1] in the map function. However, if the hour passed the tryParse check but has an unexpected time format that doesn't contain a space, calling .split(' ')[1] will throw an IndexError. Consider adding validation or using a safer approach like checking the split result length before accessing index 1.

Suggested change
'time': hour['time'].split(' ')[1],
'time': (hour['time'] is String && hour['time'].split(' ').length > 1)
? hour['time'].split(' ')[1]
: hour['time'],

Copilot uses AI. Check for mistakes.
Expand Down Expand Up @@ -194,6 +195,7 @@ class _ForecastPageState extends State<ForecastPage> {
}

Widget _buildHourlyForecast() {
if (_hourlyForecast.isEmpty) return const SizedBox.shrink();
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expand Down Expand Up @@ -234,6 +236,11 @@ class _ForecastPageState extends State<ForecastPage> {
'https:${hour['icon']}',
width: 40,
height: 40,
errorBuilder: (context, error, stackTrace) => Icon(
Icons.cloud,
size: 40,
color: Theme.of(context).colorScheme.onPrimaryContainer,
),
),
Text(
widget.useMetricSystem
Expand Down Expand Up @@ -300,6 +307,11 @@ class _ForecastPageState extends State<ForecastPage> {
'https:${day['icon']}',
width: 40,
height: 40,
errorBuilder: (context, error, stackTrace) => Icon(
Icons.cloud,
size: 40,
color: Theme.of(context).colorScheme.onSurface,
),
),
const SizedBox(width: 12),
Expanded(
Expand All @@ -312,8 +324,8 @@ class _ForecastPageState extends State<ForecastPage> {
if (day['chance_of_rain'] > 0)
Row(
children: [
Icon(Icons.water_drop, size: 12, color: Colors.blue),
Text('${day['chance_of_rain']}%', style: TextStyle(fontSize: 12, color: Colors.blue)),
Icon(Icons.water_drop, size: 12, color: Theme.of(context).colorScheme.primary),
Text('${day['chance_of_rain']}%', style: TextStyle(fontSize: 12, color: Theme.of(context).colorScheme.primary)),
],
)
],
Expand Down
55 changes: 26 additions & 29 deletions lib/screens/weather_home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
import 'package:http/http.dart' as http;
import 'package:flutter_animate/flutter_animate.dart';
import 'package:intl/intl.dart';
import 'dart:convert';
import '../models/weather_data.dart';
import '../constants/api_constants.dart';
Expand Down Expand Up @@ -235,33 +236,24 @@ class _WeatherHomePageState extends State<WeatherHomePage> {
Widget _buildHeader() {
return Padding(
padding: const EdgeInsets.all(16),
child: SearchAnchor(
builder: (BuildContext context, SearchController controller) {
return SearchBar(
controller: _cityController,
hintText: 'Search city...',
padding: const MaterialStatePropertyAll<EdgeInsets>(
EdgeInsets.symmetric(horizontal: 16.0)),
onSubmitted: (_) => _fetchWeather(),
leading: const Icon(Icons.search),
trailing: [
IconButton(
icon: const Icon(Icons.my_location),
onPressed: _fetchWeatherByLocation,
tooltip: 'Use My Location',
),
],
elevation: MaterialStateProperty.all(0),
backgroundColor: MaterialStateProperty.all(
Theme.of(context).colorScheme.surfaceContainerHighest,
),
);
},
suggestionsBuilder: (BuildContext context, SearchController controller) {
return List<ListTile>.generate(0, (int index) {
return ListTile(title: Text('Item $index'));
});
},
child: SearchBar(
controller: _cityController,
hintText: 'Search city...',
padding: const MaterialStatePropertyAll<EdgeInsets>(
EdgeInsets.symmetric(horizontal: 16.0)),
onSubmitted: (_) => _fetchWeather(),
leading: const Icon(Icons.search),
trailing: [
IconButton(
icon: const Icon(Icons.my_location),
onPressed: _fetchWeatherByLocation,
tooltip: 'Use My Location',
),
],
elevation: MaterialStateProperty.all(0),
backgroundColor: MaterialStateProperty.all(
Theme.of(context).colorScheme.surfaceContainerHighest,
),
),
);
}
Expand Down Expand Up @@ -377,7 +369,7 @@ class _WeatherHomePageState extends State<WeatherHomePage> {
),
),
Text(
DateTime.now().toString().split(' ')[0], // Simple date
DateFormat.yMMMMd().format(DateTime.now()),
style: textTheme.bodyLarge?.copyWith(
color: colorScheme.onPrimaryContainer.withOpacity(0.7),
),
Expand Down Expand Up @@ -407,6 +399,11 @@ class _WeatherHomePageState extends State<WeatherHomePage> {
width: 100,
height: 100,
fit: BoxFit.cover,
errorBuilder: (context, error, stackTrace) => Icon(
Icons.wb_sunny,
size: 80,
color: colorScheme.onPrimaryContainer,
),
)
: Icon(Icons.wb_sunny, size: 80, color: colorScheme.onPrimaryContainer),
],
Expand Down Expand Up @@ -442,7 +439,7 @@ class _WeatherHomePageState extends State<WeatherHomePage> {
_buildStatCard(
Icons.water_drop_outlined,
'Humidity',
'${_currentWeatherData!.humidity?.toStringAsFixed(0)}%',
'${_currentWeatherData!.humidity?.toStringAsFixed(0) ?? 'N/A'}%',
colorScheme.secondaryContainer,
colorScheme.onSecondaryContainer,
),
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ dependencies:
permission_handler: ^11.0.1 # Added for handling permissions
url_launcher: ^6.2.2
path_provider: ^2.1.2 # Added for file system access
intl: ^0.19.0 # Added for date formatting

dev_dependencies:
flutter_test:
Expand Down
Loading