Skip to content

Commit

Permalink
plans: fix what's new dialog keep showing up on plan changes (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
wfleischer authored Dec 4, 2024
1 parent 5a92ee1 commit f650748
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 45 deletions.
6 changes: 4 additions & 2 deletions integration_test/app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,8 @@ void main() async {
await tester.tap(find.byIcon(Icons.auto_mode));
await tester.pumpAndSettle();

expect(Theme.of(context).brightness, SchedulerBinding.instance.platformDispatcher.platformBrightness);
expect(Theme.of(context).brightness,
SchedulerBinding.instance.platformDispatcher.platformBrightness);

await tester.tap(find.byIcon(Icons.dark_mode));
await tester.pumpAndSettle();
Expand All @@ -1077,7 +1078,8 @@ void main() async {
await tester.tap(find.byIcon(Icons.auto_mode));
await tester.pumpAndSettle();

expect(Theme.of(context).brightness, SchedulerBinding.instance.platformDispatcher.platformBrightness);
expect(Theme.of(context).brightness,
SchedulerBinding.instance.platformDispatcher.platformBrightness);

await tester.pageBack();
await tester.pumpAndSettle();
Expand Down
32 changes: 32 additions & 0 deletions lib/src/plans/presentations/plans_grid.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:nwt_reading/src/localization/app_localizations_getter.dart';
import 'package:nwt_reading/src/plans/entities/plans.dart';
import 'package:nwt_reading/src/plans/presentations/plan_card.dart';

class PlansGrid extends ConsumerWidget {
const PlansGrid({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
final plans = ref.watch(plansProvider);

return plans.plans.isEmpty
? Center(
key: const Key('no-plan-yet'),
child: Text(context.loc.plansPageNoPlanYet),
)
: GridView.extent(
childAspectRatio: 1.6,
maxCrossAxisExtent: 600,
padding: const EdgeInsets.all(20),
crossAxisSpacing: 20,
mainAxisSpacing: 20,
restorationId: 'plansView',
children: buildPlansGrid(plans),
);
}

List<PlanCard> buildPlansGrid(Plans plans) =>
plans.plans.map((plan) => PlanCard(plan.id)).toList();
}
70 changes: 27 additions & 43 deletions lib/src/plans/presentations/plans_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:nwt_reading/src/localization/app_localizations_getter.dart';
import 'package:nwt_reading/src/plans/entities/plans.dart';
import 'package:nwt_reading/src/plans/presentations/plan_card.dart';
import 'package:nwt_reading/src/plans/presentations/plan_edit_dialog.dart';
import 'package:nwt_reading/src/plans/presentations/plans_grid.dart';
import 'package:nwt_reading/src/settings/stories/settings_story.dart';
import 'package:nwt_reading/src/whats_new/presentations/whats_new_dialog.dart';

Expand All @@ -14,56 +15,39 @@ class PlansPage extends ConsumerWidget {
static const routeName = '/';

@override
Widget build(BuildContext context, WidgetRef ref) {
final plans = ref.watch(plansProvider);
final seenWhatsNewVersion =
ref.watch(settingsProvider).value?.seenWhatsNewVersion;

return FutureBuilder(
future: _showWhatsNewDialog(context, ref, seenWhatsNewVersion),
builder: (context, snapshot) => Scaffold(
appBar: AppBar(
title: Text(context.loc.plansPageTitle),
actions: [
IconButton(
icon: const Icon(Icons.settings),
onPressed: () {
Navigator.restorablePushNamed(context, SettingsPage.routeName);
},
),
],
),
body: plans.plans.isEmpty
? Center(
key: const Key('no-plan-yet'),
child: Text(context.loc.plansPageNoPlanYet),
)
: GridView.extent(
childAspectRatio: 1.6,
maxCrossAxisExtent: 600,
padding: const EdgeInsets.all(20),
crossAxisSpacing: 20,
mainAxisSpacing: 20,
restorationId: 'plansView',
children: buildPlansGrid(plans),
Widget build(BuildContext context, WidgetRef ref) => FutureBuilder(
future: _showWhatsNewDialog(context, ref),
builder: (context, snapshot) => Scaffold(
appBar: AppBar(
title: Text(context.loc.plansPageTitle),
actions: [
IconButton(
icon: const Icon(Icons.settings),
onPressed: () {
Navigator.restorablePushNamed(
context, SettingsPage.routeName);
},
),
floatingActionButton: FloatingActionButton(
tooltip: context.loc.plansPageAddPlanTooltip,
onPressed: () => showDialog<String>(
context: context,
builder: (BuildContext context) => PlanEditDialog(),
],
),
body: PlansGrid(),
floatingActionButton: FloatingActionButton(
tooltip: context.loc.plansPageAddPlanTooltip,
onPressed: () => showDialog<String>(
context: context,
builder: (BuildContext context) => PlanEditDialog(),
),
child: const Icon(Icons.add),
),
child: const Icon(Icons.add),
),
),
);
}
);

List<PlanCard> buildPlansGrid(Plans plans) =>
plans.plans.map((plan) => PlanCard(plan.id)).toList();

Future<void> _showWhatsNewDialog(
BuildContext context, WidgetRef ref, String? seenWhatsNewVersion) async {
Future<void> _showWhatsNewDialog(BuildContext context, WidgetRef ref) async {
final seenWhatsNewVersion =
(await ref.read(settingsProvider.future)).seenWhatsNewVersion;
WidgetsBinding.instance.addPostFrameCallback((duration) {
showWhatsNewDialog(context, ref, seenWhatsNewVersion);
});
Expand Down

0 comments on commit f650748

Please sign in to comment.