Skip to content

Commit

Permalink
show am pm thingy in the time period screen
Browse files Browse the repository at this point in the history
  • Loading branch information
user5522 committed Jun 3, 2024
1 parent 7c9ca74 commit 6af7b1c
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions lib/components/settings/screens/timetable_period_screen.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:timetable/constants/custom_times.dart';
import 'package:timetable/extensions/time_of_day.dart';
import 'package:timetable/helpers/time_management.dart';
import 'package:timetable/provider/settings.dart';
Expand All @@ -20,6 +19,8 @@ class TimetablePeriodScreen extends ConsumerWidget {
final twentyFourHours = ref.watch(settingsProvider).twentyFourHours;
final settings = ref.read(settingsProvider.notifier);

final uses24HoursFormat = MediaQuery.of(context).alwaysUse24HourFormat;

/// error dialog when the start time and end time have the same value (equal)
void showInvalidEqualTimeDialog() {
showDialog(
Expand Down Expand Up @@ -57,6 +58,24 @@ class TimetablePeriodScreen extends ConsumerWidget {
return;
}

String getTime(TimeOfDay time) {
final formattedTimeHour = time.hour < 10
? "0${time.hour}"
: uses24HoursFormat
? time.hour
: time.hour > 12
? time.hour - 12
: time.hour;
final amORpm = time.hour > 12 ? "PM" : "AM";
final formattedTimeMinute = time.minute == 0
? "00"
: time.minute < 10
? "0${time.minute}"
: "${time.minute}";

return "$formattedTimeHour:$formattedTimeMinute${uses24HoursFormat ? "" : " $amORpm"}";
}

return Scaffold(
appBar: AppBar(
title: const Text("period_preferences").tr(),
Expand Down Expand Up @@ -94,9 +113,7 @@ class TimetablePeriodScreen extends ConsumerWidget {
ListTile(
title: const Text("start_time").tr(),
enabled: customTimePeriod ? true : false,
subtitle: Text(
"${getCustomTimeHour(customStartTime)}:${getCustomTimeMinute(customStartTime)}",
),
subtitle: Text(getTime(customStartTime)),
onTap: () async {
final TimeOfDay? selectedTime = await timePicker(
context,
Expand All @@ -120,9 +137,7 @@ class TimetablePeriodScreen extends ConsumerWidget {
ListTile(
title: const Text("end_time").tr(),
enabled: customTimePeriod ? true : false,
subtitle: Text(
"${getCustomTimeHour(customEndTime)}:${getCustomTimeMinute(customEndTime)}",
),
subtitle: Text(getTime(customEndTime)),
onTap: () async {
final TimeOfDay? selectedTime = await timePicker(
context,
Expand Down

0 comments on commit 6af7b1c

Please sign in to comment.