From f6507480e8935e1dd3d6dc6efbe29516eb81181a Mon Sep 17 00:00:00 2001 From: Werner Fleischer <70745309+wfleischer@users.noreply.github.com> Date: Wed, 4 Dec 2024 21:50:03 +0100 Subject: [PATCH] plans: fix what's new dialog keep showing up on plan changes (#150) --- integration_test/app_test.dart | 6 +- lib/src/plans/presentations/plans_grid.dart | 32 ++++++++++ lib/src/plans/presentations/plans_page.dart | 70 ++++++++------------- 3 files changed, 63 insertions(+), 45 deletions(-) create mode 100644 lib/src/plans/presentations/plans_grid.dart diff --git a/integration_test/app_test.dart b/integration_test/app_test.dart index 565d21c..213abe6 100644 --- a/integration_test/app_test.dart +++ b/integration_test/app_test.dart @@ -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(); @@ -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(); diff --git a/lib/src/plans/presentations/plans_grid.dart b/lib/src/plans/presentations/plans_grid.dart new file mode 100644 index 0000000..a20f4e5 --- /dev/null +++ b/lib/src/plans/presentations/plans_grid.dart @@ -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 buildPlansGrid(Plans plans) => + plans.plans.map((plan) => PlanCard(plan.id)).toList(); +} diff --git a/lib/src/plans/presentations/plans_page.dart b/lib/src/plans/presentations/plans_page.dart index 849623c..ddb3187 100644 --- a/lib/src/plans/presentations/plans_page.dart +++ b/lib/src/plans/presentations/plans_page.dart @@ -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'; @@ -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( - context: context, - builder: (BuildContext context) => PlanEditDialog(), + ], + ), + body: PlansGrid(), + floatingActionButton: FloatingActionButton( + tooltip: context.loc.plansPageAddPlanTooltip, + onPressed: () => showDialog( + context: context, + builder: (BuildContext context) => PlanEditDialog(), + ), + child: const Icon(Icons.add), ), - child: const Icon(Icons.add), ), - ), - ); - } + ); List buildPlansGrid(Plans plans) => plans.plans.map((plan) => PlanCard(plan.id)).toList(); - Future _showWhatsNewDialog( - BuildContext context, WidgetRef ref, String? seenWhatsNewVersion) async { + Future _showWhatsNewDialog(BuildContext context, WidgetRef ref) async { + final seenWhatsNewVersion = + (await ref.read(settingsProvider.future)).seenWhatsNewVersion; WidgetsBinding.instance.addPostFrameCallback((duration) { showWhatsNewDialog(context, ref, seenWhatsNewVersion); });