refactor(meditate): the player's buttons read their cubit as they are pressed

leancode_lint's avoid_context_read_in_build, which only the root's analysis
runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
Tizian 「ティツィアーン」 2026-11-03 16:51:04 +01:00
commit abac248b76
Signed by: raisondetredev
GPG key ID: 07F6FCF405488B64

View file

@ -57,7 +57,6 @@ class const _Listening({required final ListeningPlan plan})
final l10n = AppLocalizations.of(context); final l10n = AppLocalizations.of(context);
final theme = Theme.of(context); final theme = Theme.of(context);
final state = context.watch<ListeningCubit>().state; final state = context.watch<ListeningCubit>().state;
final cubit = context.read<ListeningCubit>();
final length = plan.length; final length = plan.length;
final position = state.position > length ? length : state.position; final position = state.position > length ? length : state.position;
return TopGradient( return TopGradient(
@ -126,7 +125,9 @@ class const _Listening({required final ListeningPlan plan})
onChanged: state.phase == ListeningPhase.loading onChanged: state.phase == ListeningPhase.loading
? null ? null
: (value) => unawaited( : (value) => unawaited(
cubit.seek(Duration(milliseconds: value.round())), context.read<ListeningCubit>().seek(
Duration(milliseconds: value.round()),
),
), ),
), ),
Row( Row(
@ -143,13 +144,15 @@ class const _Listening({required final ListeningPlan plan})
FilledButton.icon( FilledButton.icon(
icon: const Icon(LucideIcons.play), icon: const Icon(LucideIcons.play),
label: Text(l10n.libraryResume), label: Text(l10n.libraryResume),
onPressed: () => unawaited(cubit.resume()), onPressed: () =>
unawaited(context.read<ListeningCubit>().resume()),
) )
else else
FilledButton.tonalIcon( FilledButton.tonalIcon(
icon: const Icon(LucideIcons.pause), icon: const Icon(LucideIcons.pause),
label: Text(l10n.libraryPause), label: Text(l10n.libraryPause),
onPressed: () => unawaited(cubit.pause()), onPressed: () =>
unawaited(context.read<ListeningCubit>().pause()),
), ),
], ],
}, },