Skip to content

Commit

Permalink
[ui] follow system time format
Browse files Browse the repository at this point in the history
  • Loading branch information
triallax committed Jun 28, 2022
1 parent ce476e9 commit e6c31d8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
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

0 comments on commit e6c31d8

Please sign in to comment.