Skip to content

Commit

Permalink
plans: default the language of a new plan to the UI language (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
wfleischer authored Jan 6, 2025
1 parent 0ec7e1c commit 917a326
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion integration_test/app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,12 @@ void main() async {
await tester.pumpAndSettle();

Plan plan = providerContainer.read(plansProvider).plans.first;
buildContext = tester.element(find.byKey(const Key('plans-grid')));
expect(plan.name, null);
expect(plan.scheduleKey.type, ScheduleType.chronological);
expect(plan.scheduleKey.duration, ScheduleDuration.y1);
expect(plan.scheduleKey.version, '1.0');
expect(plan.language, 'en');
expect(plan.language, Localizations.localeOf(buildContext).languageCode);
expect(plan.withTargetDate, true);
expect(plan.showEvents, true);
expect(plan.showLocations, false);
Expand Down
4 changes: 2 additions & 2 deletions lib/src/plans/entities/plan.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class Plan extends Equatable {
required this.id,
this.name,
required this.scheduleKey,
required this.language,
this.language,
required this.bookmark,
this.startDate,
this.lastDate,
Expand All @@ -148,7 +148,7 @@ class Plan extends Equatable {
final String id;
final String? name;
final ScheduleKey scheduleKey;
final String language;
final String? language;
final Bookmark bookmark;
final DateTime? startDate;
final DateTime? lastDate;
Expand Down
1 change: 0 additions & 1 deletion lib/src/plans/entities/plans.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class PlansNotifier extends Notifier<Plans> {
return Plan(
id: planId,
scheduleKey: scheduleKey,
language: 'en',
bookmark: const Bookmark(dayIndex: 0, sectionIndex: -1),
withTargetDate: true,
showEvents: true,
Expand Down
5 changes: 5 additions & 0 deletions lib/src/plans/presentations/plan_language_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ class PlanLanguageTile extends ConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
final plan = ref.watch(planEditProviderFamily(planId));
final planEdit = ref.read(planEditProviderFamily(planId).notifier);
Future.microtask(() {
if (plan.language == null && context.mounted) {
planEdit.updateLanguage(Localizations.localeOf(context).languageCode);
}
});
final bibleLanguages = ref.watch(bibleLanguagesProvider).valueOrNull;

return ListTile(
Expand Down
4 changes: 3 additions & 1 deletion lib/src/plans/presentations/plans_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ class PlansPageState extends ConsumerState<PlansPage> {
),
],
),
body: PlansGrid(),
body: PlansGrid(
key: const Key('plans-grid'),
),
floatingActionButton: FloatingActionButton(
tooltip: context.loc.plansPageAddPlanTooltip,
onPressed: () => showDialog<String>(
Expand Down
2 changes: 1 addition & 1 deletion lib/src/plans/repositories/plans_serializer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class PlansSerializer {
'id': plan.id,
if (plan.name != null) 'name': plan.name,
'scheduleKey': _convertScheduleKeyToMap(plan.scheduleKey),
'language': plan.language,
if (plan.language != null) 'language': plan.language,
'bookmark': _convertBookmarkToMap(plan.bookmark),
if (plan.startDate != null)
'startDate': plan.startDate!.toIso8601String(),
Expand Down

0 comments on commit 917a326

Please sign in to comment.