Skip to content

Commit e90a849

Browse files
madenvelclaude
andcommitted
Fix semantics crash when clearing the queue
Clearing the queue leaves no current track, so NowPlayingContent passed enabled: false to PlaybackProgressSlider, which set Slider.onChanged to null. That tears down the slider's interactive semantics (focus node, increase/decrease actions) in the same frame the confirm dialog pops, and flushSemantics then asserts on identical(childRenderObject, parentRenderObject). Only reproduces with accessibility semantics on. Same family as flutter/flutter#189902. The callbacks now stay non-null and gate internally; disabled is an always-mounted IgnorePointer, which flips isBlockingUserActions rather than restructuring the semantics tree, so the slider stays correctly inert to a screen reader. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent 6b61047 commit e90a849

2 files changed

Lines changed: 239 additions & 69 deletions

File tree

‎lib/widgets/playback_progress_slider.dart‎

Lines changed: 81 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -81,78 +81,90 @@ class _PlaybackProgressSliderState
8181
return RepaintBoundary(
8282
child: Opacity(
8383
opacity: widget.enabled ? 1.0 : 0.4,
84-
child: Column(
85-
children: [
86-
SliderTheme(
87-
data: SliderThemeData(
88-
trackHeight: 3,
89-
thumbShape: const RoundSliderThumbShape(enabledThumbRadius: 6),
90-
overlayShape: const RoundSliderOverlayShape(overlayRadius: 14),
91-
activeTrackColor: KalinkaColors.accent,
92-
inactiveTrackColor: KalinkaColors.borderDefault,
93-
thumbColor: Colors.white,
94-
overlayColor: KalinkaColors.accent.withValues(alpha: 0.25),
95-
),
96-
child: Slider(
97-
value: progress,
98-
onChanged: !widget.enabled
99-
? null
100-
: (value) {
101-
if (!_isSeeking) {
102-
KalinkaHaptics.mediumImpact();
103-
_lastHapticSeekPosition = value;
104-
} else if ((value - _lastHapticSeekPosition).abs() >=
105-
0.05) {
106-
KalinkaHaptics.selectionClick();
107-
_lastHapticSeekPosition = value;
108-
}
109-
setState(() {
110-
_isSeeking = true;
111-
_seekProgress = value;
112-
_seekPositionMs = (value * widget.durationMs).toInt();
113-
});
114-
},
115-
onChangeEnd: (value) {
116-
KalinkaHaptics.lightImpact();
117-
final newPositionMs = (value * widget.durationMs).toInt();
118-
setState(() {
119-
_seekBeforeSeq = ref.read(playQueueStateStoreProvider).seq;
120-
});
121-
ref
122-
.read(kalinkaWsApiProvider)
123-
.sendQueueCommand(
124-
QueueCommand.seek(positionMs: newPositionMs),
125-
);
126-
},
84+
child: IgnorePointer(
85+
ignoring: !widget.enabled,
86+
child: Column(
87+
children: [
88+
SliderTheme(
89+
data: SliderThemeData(
90+
trackHeight: 3,
91+
thumbShape: const RoundSliderThumbShape(
92+
enabledThumbRadius: 6,
93+
),
94+
overlayShape: const RoundSliderOverlayShape(
95+
overlayRadius: 14,
96+
),
97+
activeTrackColor: KalinkaColors.accent,
98+
inactiveTrackColor: KalinkaColors.borderDefault,
99+
thumbColor: Colors.white,
100+
overlayColor: KalinkaColors.accent.withValues(alpha: 0.25),
101+
),
102+
// Disabled via the IgnorePointer above, never a null onChanged:
103+
// that restructures the Slider's semantics, which asserts in
104+
// flushSemantics if a dialog pops the same frame (Clear all).
105+
child: Slider(
106+
value: progress,
107+
onChanged: (value) {
108+
if (!widget.enabled) return;
109+
if (!_isSeeking) {
110+
KalinkaHaptics.mediumImpact();
111+
_lastHapticSeekPosition = value;
112+
} else if ((value - _lastHapticSeekPosition).abs() >=
113+
0.05) {
114+
KalinkaHaptics.selectionClick();
115+
_lastHapticSeekPosition = value;
116+
}
117+
setState(() {
118+
_isSeeking = true;
119+
_seekProgress = value;
120+
_seekPositionMs = (value * widget.durationMs).toInt();
121+
});
122+
},
123+
onChangeEnd: (value) {
124+
if (!widget.enabled) return;
125+
KalinkaHaptics.lightImpact();
126+
final newPositionMs = (value * widget.durationMs).toInt();
127+
setState(() {
128+
_seekBeforeSeq = ref
129+
.read(playQueueStateStoreProvider)
130+
.seq;
131+
});
132+
ref
133+
.read(kalinkaWsApiProvider)
134+
.sendQueueCommand(
135+
QueueCommand.seek(positionMs: newPositionMs),
136+
);
137+
},
138+
),
127139
),
128-
),
129-
// SizedBox gives tight constraints (tight width from Column + fixed
130-
// height here), making the Row a Flutter relayout boundary. This
131-
// prevents RenderParagraph.markNeedsLayout() from propagating up
132-
// through the RepaintBoundary and causing a full-screen relayout on
133-
// every playback-time tick.
134-
SizedBox(
135-
width: double
136-
.infinity, // combined with height → tight on both axes → relayout boundary
137-
height: 20,
138-
child: Padding(
139-
padding: const EdgeInsets.symmetric(horizontal: 4),
140-
child: Row(
141-
mainAxisAlignment: MainAxisAlignment.spaceBetween,
142-
children: [
143-
Text(
144-
_formatTime(positionMs),
145-
style: KalinkaTextStyles.timeLabel,
146-
),
147-
Text(
148-
_formatTime(widget.durationMs),
149-
style: KalinkaTextStyles.timeLabel,
150-
),
151-
],
140+
// SizedBox gives tight constraints (tight width from Column + fixed
141+
// height here), making the Row a Flutter relayout boundary. This
142+
// prevents RenderParagraph.markNeedsLayout() from propagating up
143+
// through the RepaintBoundary and causing a full-screen relayout on
144+
// every playback-time tick.
145+
SizedBox(
146+
width: double
147+
.infinity, // combined with height → tight on both axes → relayout boundary
148+
height: 20,
149+
child: Padding(
150+
padding: const EdgeInsets.symmetric(horizontal: 4),
151+
child: Row(
152+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
153+
children: [
154+
Text(
155+
_formatTime(positionMs),
156+
style: KalinkaTextStyles.timeLabel,
157+
),
158+
Text(
159+
_formatTime(widget.durationMs),
160+
style: KalinkaTextStyles.timeLabel,
161+
),
162+
],
163+
),
152164
),
153165
),
154-
),
155-
],
166+
],
167+
),
156168
),
157169
),
158170
);
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
import 'dart:async' show Completer;
2+
3+
import 'package:flutter/material.dart';
4+
import 'package:flutter_riverpod/flutter_riverpod.dart';
5+
import 'package:flutter_test/flutter_test.dart';
6+
import 'package:shared_preferences/shared_preferences.dart';
7+
import 'package:kalinka/data_model/data_model.dart';
8+
import 'package:kalinka/data_model/playqueue_events.dart';
9+
import 'package:kalinka/providers/app_state_provider.dart';
10+
import 'package:kalinka/providers/connection_settings_provider.dart';
11+
import 'package:kalinka/providers/connection_state_provider.dart';
12+
import 'package:kalinka/providers/kalinka_player_api_provider.dart';
13+
import 'package:kalinka/providers/onboarding_provider.dart';
14+
import 'package:kalinka/providers/playback_time_provider.dart';
15+
import 'package:kalinka/providers/source_modules_provider.dart';
16+
import 'package:kalinka/providers/url_resolver.dart';
17+
import 'package:kalinka/providers/websocket_provider.dart';
18+
import 'package:kalinka/screens/music_player_screen.dart';
19+
import 'package:kalinka/widgets/clear_all_confirm_dialog.dart';
20+
import 'package:web_socket_channel/web_socket_channel.dart';
21+
22+
// Full-screen repro for the clear-all crash with semantics enabled (TalkBack):
23+
// 'identical(childRenderObject, parentRenderObject)' assertion in
24+
// _SemanticsGeometry.computeChildGeometry during flushSemantics.
25+
26+
class _SettableQueueNotifier extends PlayQueueStateStore {
27+
_SettableQueueNotifier(this._initial);
28+
final PlayQueueState _initial;
29+
@override
30+
PlayQueueState build() => _initial;
31+
void set(PlayQueueState s) => state = s;
32+
}
33+
34+
class _FakeConnectionNotifier extends ConnectionStateNotifier {
35+
@override
36+
ConnectionStatus build() => ConnectionStatus.connected;
37+
}
38+
39+
class _FakePlaybackTimeNotifier extends PlaybackTimeMsNotifier {
40+
@override
41+
int build() => 0;
42+
}
43+
44+
class _FakeApi implements KalinkaPlayerProxy {
45+
_FakeApi(this.onClear);
46+
final void Function() onClear;
47+
48+
@override
49+
Future<void> clear() async => onClear();
50+
51+
@override
52+
dynamic noSuchMethod(Invocation invocation) =>
53+
throw UnimplementedError('${invocation.memberName}');
54+
}
55+
56+
Track _track(String id) => Track(
57+
id: id,
58+
title: 'Track $id',
59+
duration: 200000,
60+
performer: Artist(id: 'a', name: 'Someone'),
61+
);
62+
63+
PlayQueueState _queueWithTracks() => PlayQueueState(
64+
playbackState: PlaybackState(state: PlayerStateType.playing, index: 2),
65+
trackList: [_track('a'), _track('b'), _track('c'), _track('d'), _track('e')],
66+
playbackMode: PlaybackMode.empty,
67+
seq: 0,
68+
);
69+
70+
PlayQueueState _emptyQueue() => PlayQueueState(
71+
playbackState: PlaybackState(state: PlayerStateType.stopped, index: null),
72+
trackList: const [],
73+
playbackMode: PlaybackMode.empty,
74+
seq: 1,
75+
);
76+
77+
void main() {
78+
testWidgets('clear all from the tray with semantics enabled does not throw', (
79+
tester,
80+
) async {
81+
// Tablet/desktop layout (>= 900px wide) — matches the Linux desktop
82+
// window where the crash was reported.
83+
tester.view.physicalSize = const Size(1280, 720);
84+
tester.view.devicePixelRatio = 1.0;
85+
addTearDown(tester.view.reset);
86+
final semantics = tester.ensureSemantics();
87+
SharedPreferences.setMockInitialValues({
88+
'Kalinka.host': 'localhost',
89+
'Kalinka.port': 8080,
90+
'Kalinka.name': 'Test',
91+
OnboardingStatusNotifier.sharedPrefOobeComplete: true,
92+
OnboardingStatusNotifier.sharedPrefCoachMarksShown: true,
93+
});
94+
final prefs = await SharedPreferences.getInstance();
95+
final queueNotifier = _SettableQueueNotifier(_queueWithTracks());
96+
final api = _FakeApi(() => queueNotifier.set(_emptyQueue()));
97+
98+
await tester.pumpWidget(
99+
ProviderScope(
100+
overrides: [
101+
sharedPrefsProvider.overrideWithValue(prefs),
102+
kalinkaProxyProvider.overrideWithValue(api),
103+
playQueueStateStoreProvider.overrideWith(() => queueNotifier),
104+
connectionStateProvider.overrideWith(() => _FakeConnectionNotifier()),
105+
playbackTimeMsProvider.overrideWith(
106+
() => _FakePlaybackTimeNotifier(),
107+
),
108+
sourceModulesProvider.overrideWith((ref) => <ModuleInfo>[]),
109+
// The real family dials a socket and arms a 5s connect timeout that
110+
// outlives the test; a never-completing future keeps it inert.
111+
webSocketProvider.overrideWith(
112+
(ref, path) => Completer<WebSocketChannel>().future,
113+
),
114+
sourceCountProvider.overrideWithValue(1),
115+
urlResolverProvider.overrideWithValue(UrlResolver('')),
116+
],
117+
child: const MaterialApp(home: MusicPlayerScreen()),
118+
),
119+
);
120+
await tester.pumpAndSettle();
121+
122+
// Open the queue management tray.
123+
await tester.tap(find.byIcon(Icons.more_vert).first);
124+
await tester.pumpAndSettle();
125+
expect(find.text('Clear all'), findsOneWidget);
126+
127+
// Pick "Clear all" → tray closes, 160ms delay, confirm dialog opens.
128+
await tester.tap(find.text('Clear all'));
129+
await tester.pumpAndSettle();
130+
await tester.pump(const Duration(milliseconds: 200));
131+
await tester.pumpAndSettle();
132+
expect(find.text('Clear entire queue?'), findsOneWidget);
133+
134+
// Confirm — the queue empties behind the dialog as it pops, which is the
135+
// frame that used to assert.
136+
await tester.tap(
137+
find.descendant(
138+
of: find.byType(ClearAllConfirmDialog),
139+
matching: find.text('Clear all'),
140+
),
141+
);
142+
await tester.pump();
143+
expect(tester.takeException(), isNull);
144+
await tester.pump(const Duration(milliseconds: 50));
145+
expect(tester.takeException(), isNull);
146+
await tester.pumpAndSettle(const Duration(milliseconds: 100));
147+
expect(tester.takeException(), isNull);
148+
149+
expect(find.text('Clear entire queue?'), findsNothing);
150+
expect(find.text('Nothing Queued'), findsOneWidget);
151+
152+
// Let the toast expire so no timers outlive the test.
153+
await tester.pump(const Duration(seconds: 10));
154+
await tester.pumpAndSettle();
155+
156+
semantics.dispose();
157+
});
158+
}

0 commit comments

Comments
 (0)