Skip to content
This repository has been archived by the owner on Aug 26, 2023. It is now read-only.

[ui] follow system time format #327

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import 'package:clima/ui/themes/light_theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:intl/date_symbol_data_local.dart';
import 'package:intl/intl_standalone.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:sizer/sizer.dart';

Expand All @@ -34,6 +36,9 @@ Future<void> main({
Widget Function(Widget widget)? topLevelBuilder,
Locale? Function(BuildContext)? getLocale,
}) async {
await findSystemLocale();
await initializeDateFormatting();

// Unless you do this, using method channels (like `SharedPreferences` does)
// before running `runApp` throws an error.
WidgetsFlutterBinding.ensureInitialized();
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/screens/weather_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class WeatherScreen extends HookConsumerWidget {
: Row(
children: [
Text(
'Updated ${DateFormat.Md().add_jm().format(fullWeather.currentWeather.date.toLocal())} · ',
'Updated ${DateFormat.Md().addPattern(MediaQuery.of(context).alwaysUse24HourFormat ? 'Hm' : 'jm').format(fullWeather.currentWeather.date.toLocal())} · ',
style: TextStyle(
color: Theme.of(context).textTheme.subtitle2!.color,
fontSize: MediaQuery.of(context).size.shortestSide <
Expand Down
8 changes: 6 additions & 2 deletions lib/ui/widgets/weather/additional_info_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class AdditionalInfoWidget extends ConsumerWidget {
),
);

final timeFormat = MediaQuery.of(context).alwaysUse24HourFormat
? DateFormat.Hm()
: DateFormat.jm();

return Column(
children: [
Padding(
Expand Down Expand Up @@ -107,13 +111,13 @@ class AdditionalInfoWidget extends ConsumerWidget {
children: [
AdditionalInfoTile(
title: 'Sunrise',
value: DateFormat.Hm().format(
value: timeFormat.format(
currentDayForecast.sunrise.toUtc().add(timeZoneOffset),
),
),
AdditionalInfoTile(
title: 'Sunset',
value: DateFormat.Hm().format(
value: timeFormat.format(
currentDayForecast.sunset.toUtc().add(timeZoneOffset),
),
),
Expand Down
5 changes: 4 additions & 1 deletion lib/ui/widgets/weather/hourly_forecasts_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ class HourlyForecastsWidget extends ConsumerWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
DateFormat.j().format(
(MediaQuery.of(context).alwaysUse24HourFormat
? DateFormat.Hm()
: DateFormat.jm())
.format(
hourlyForecast.date.toUtc().add(timeZoneOffset),
),
style: kSubtitle2TextStyle(context),
Expand Down