Skip to content

Commit cf21738

Browse files
authored
plans: use i18n to format the dates on the plan edit dialog (#134)
1 parent a810f9a commit cf21738

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed

lib/src/localization/app_en.arb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@
100100
"description": "The with target date status subtitle on the plan edit page",
101101
"placeholders": {
102102
"targetDate": {
103-
"type": "String"
103+
"type": "DateTime",
104+
"format": "yMd"
104105
},
105106
"direction": {
106107
"type": "String"
@@ -119,7 +120,8 @@
119120
"description": "The reset target date subtitle on the plan edit page",
120121
"placeholders": {
121122
"targetDate": {
122-
"type": "String"
123+
"type": "DateTime",
124+
"format": "yMd"
123125
}
124126
}
125127
},

lib/src/plans/presentations/plan_edit_dialog.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ class PlanEditDialog extends ConsumerWidget {
5757
const SizedBox(height: 20),
5858
PlanLanguageTile(planId),
5959
PlanWithTargetDateTile(planId),
60-
if (plan.withTargetDate && plan.targetDate != adjustedTargetDate)
61-
PlanResetTargetDateTile(planId),
60+
if (plan.withTargetDate &&
61+
adjustedTargetDate != null &&
62+
plan.targetDate != adjustedTargetDate)
63+
PlanResetTargetDateTile(planId, adjustedTargetDate),
6264
PlanShowEventsTile(planId),
6365
PlanShowLocationsTile(planId),
6466
if (!isNewPlan)

lib/src/plans/presentations/plan_reset_target_date_tile.dart

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,23 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
44
import 'package:nwt_reading/src/plans/stories/plan_edit_story.dart';
55

66
class PlanResetTargetDateTile extends ConsumerWidget {
7-
const PlanResetTargetDateTile(this.planId, {super.key});
7+
const PlanResetTargetDateTile(this.planId, this.adjustedTargetDate,
8+
{super.key});
89

910
final String? planId;
11+
final DateTime adjustedTargetDate;
1012

1113
@override
1214
Widget build(BuildContext context, WidgetRef ref) {
1315
ref.watch(planEditProviderFamily(planId));
1416
final planEdit = ref.read(planEditProviderFamily(planId).notifier);
15-
final adjustedTargetDate = planEdit.calcTargetDate();
16-
final formattedAdjustedTargetDate = adjustedTargetDate != null
17-
? MaterialLocalizations.of(context)
18-
.formatCompactDate(adjustedTargetDate)
19-
: '';
2017

2118
return ListTile(
2219
key: const Key('reset-target-date'),
2320
title:
2421
Text(AppLocalizations.of(context).planEditPageResetTargetDateTitle),
2522
subtitle: Text(AppLocalizations.of(context)
26-
.planEditPageResetTargetDateSubtitle(formattedAdjustedTargetDate)),
23+
.planEditPageResetTargetDateSubtitle(adjustedTargetDate)),
2724
trailing: Icon(Icons.arrow_forward),
2825
onTap: () {
2926
showDialog<String>(

lib/src/plans/presentations/plan_with_target_date_tile.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ class PlanWithTargetDateTile extends ConsumerWidget {
1414
final plan = ref.watch(planEditProviderFamily(planId));
1515
ref.watch(planEditProviderFamily(planId));
1616
final planEdit = ref.read(planEditProviderFamily(planId).notifier);
17-
final formattedTargetDate = plan.targetDate != null
18-
? MaterialLocalizations.of(context).formatCompactDate(plan.targetDate!)
19-
: '';
2017
final planNotifier =
2118
planId != null ? ref.read(planProviderFamily(planId!).notifier) : null;
2219
final deviationDays = planNotifier?.getDeviationDays() ?? 0;
@@ -27,12 +24,12 @@ class PlanWithTargetDateTile extends ConsumerWidget {
2724
crossAxisAlignment: CrossAxisAlignment.start,
2825
children: <Widget>[
2926
Text(AppLocalizations.of(context).planEditPageWithTargetDateSubtitle),
30-
if (planId != null && plan.withTargetDate)
27+
if (planId != null && plan.withTargetDate && plan.targetDate != null)
3128
Text(
3229
key: const Key('target-status'),
3330
AppLocalizations.of(context)
3431
.planEditPageWithTargetDateStatusSubtitle(
35-
formattedTargetDate,
32+
plan.targetDate!,
3633
deviationDays > 0
3734
? 'ahead'
3835
: deviationDays < 0

0 commit comments

Comments
 (0)