Skip to content

Commit 231fff4

Browse files
committed
read daily and weekly data based on timezone
1 parent 9bf9bac commit 231fff4

File tree

13 files changed

+353
-37
lines changed

13 files changed

+353
-37
lines changed

lib/main.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ class WeatherApp extends ConsumerWidget {
2727

2828
return initInfo.when(
2929
loading: () => const CircularProgressIndicator(),
30-
error: (err, stack) => Text('Error: $err'),
30+
error: (err, stack) {
31+
print('Error during initialization: $err');
32+
return Text('Error: $err, $stack');
33+
},
3134
data: (config) {
3235
return ProviderScope(
3336
overrides: [

lib/pages/day.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,20 @@ class DayPage extends ConsumerWidget {
1616
Widget build(BuildContext context, WidgetRef ref) {
1717
final openMateoService = ref.read(openMateoServiceProvider);
1818
final googlePlacesService = ref.read(googlePlacesServiceProvider);
19-
final position = ref.read(initInfoProvider).position;
19+
final init = ref.read(initInfoProvider);
2020

2121
return Layout(
2222
title: 'Day at a Glance',
2323
child: FutureBuilder(
2424
future: Future.wait([
2525
openMateoService.fetchHourly(
26-
position.latitude,
27-
position.longitude,
26+
latitude: init.position.latitude,
27+
longitude: init.position.longitude,
28+
timezone: init.timezone,
2829
),
2930
googlePlacesService.fetchNearbyLocalities(
30-
position.latitude,
31-
position.longitude,
31+
init.position.latitude,
32+
init.position.longitude,
3233
),
3334
]),
3435
builder: (context, snapshot) {

lib/pages/week.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,21 @@ class WeekPage extends ConsumerWidget {
1313
@override
1414
Widget build(BuildContext context, WidgetRef ref) {
1515
final openMateoService = ref.read(openMateoServiceProvider);
16-
final position = ref.read(initInfoProvider).position;
16+
final init = ref.read(initInfoProvider);
1717

1818
return Layout(
1919
title: 'Weekly Forecast',
2020
child: FutureBuilder(
2121
future: Future.wait([
2222
openMateoService.fetchHourly(
23-
position.latitude,
24-
position.longitude,
23+
latitude: init.position.latitude,
24+
longitude: init.position.longitude,
25+
timezone: init.timezone,
2526
),
2627
openMateoService.fetchDaily(
27-
position.latitude,
28-
position.longitude,
28+
latitude: init.position.latitude,
29+
longitude: init.position.longitude,
30+
timezone: init.timezone,
2931
),
3032
]),
3133
builder: (context, snapshot) {

lib/services/google_places/data.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,17 @@ class DisplayName with _$DisplayName {
4444
factory DisplayName.fromJson(Map<String, Object?> json) =>
4545
_$DisplayNameFromJson(json);
4646
}
47+
48+
@freezed
49+
class TimeZoneResponse with _$TimeZoneResponse {
50+
factory TimeZoneResponse({
51+
int? dstOffset,
52+
int? rawOffset,
53+
String? status,
54+
String? timeZoneId,
55+
String? timeZoneName,
56+
}) = _TimeZoneResponse;
57+
58+
factory TimeZoneResponse.fromJson(Map<String, Object?> json) =>
59+
_$TimeZoneResponseFromJson(json);
60+
}

lib/services/google_places/data.freezed.dart

Lines changed: 226 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/services/google_places/data.g.dart

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/services/google_places/google_places.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,18 @@ class GooglePlacesService {
3636

3737
return data.places ?? [];
3838
}
39+
40+
Future<TimeZoneResponse> fetchTimeZone(
41+
double latitude, double longitude) async {
42+
final response = await dio.get(
43+
'https://maps.googleapis.com/maps/api/timezone/json',
44+
queryParameters: {
45+
'location': '$latitude,$longitude',
46+
'timestamp': DateTime.now().millisecondsSinceEpoch ~/ 1000,
47+
'key': googleMapsApiKey,
48+
},
49+
);
50+
51+
return TimeZoneResponse.fromJson(response.data);
52+
}
3953
}

0 commit comments

Comments
 (0)