Skip to content

Commit 7b96711

Browse files
committed
Reset _listenToPositionStream when complete listening
1 parent ce9d70f commit 7b96711

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

lib/views/add_ons/add_ons_content.dart

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,17 @@ class _AddOnsContent extends StatelessWidget {
3131
);
3232
}
3333

34-
return ListView(
35-
padding: EdgeInsets.zero,
36-
children: [
37-
const SizedBox(height: 12.0),
38-
if (viewModel.dealEndDate != null) buildOfferDealCard(viewModel.dealEndDate!, padding, context),
39-
buildAddOnsGrid(context, padding),
40-
],
34+
return LayoutBuilder(
35+
builder: (context, constraints) {
36+
return ListView(
37+
padding: EdgeInsets.zero,
38+
children: [
39+
const SizedBox(height: 12.0),
40+
if (viewModel.dealEndDate != null) buildOfferDealCard(viewModel.dealEndDate!, padding, context),
41+
buildAddOnsGrid(context, padding, constraints),
42+
],
43+
);
44+
},
4145
);
4246
}
4347

@@ -128,8 +132,8 @@ class _AddOnsContent extends StatelessWidget {
128132
);
129133
}
130134

131-
Widget buildAddOnsGrid(BuildContext context, EdgeInsets screenPadding) {
132-
final screenWidth = MediaQuery.of(context).size.width;
135+
Widget buildAddOnsGrid(BuildContext context, EdgeInsets screenPadding, BoxConstraints constraints) {
136+
final screenWidth = constraints.maxWidth;
133137
final isLargeScreen = screenWidth > 900;
134138
final isMediumScreen = screenWidth > 600;
135139

lib/widgets/sp_voice_player.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ class _SpVoicePlayerState extends State<SpVoicePlayer> with WidgetsBindingObserv
157157

158158
// for android only, https://github.com/ryanheise/just_audio/issues/1267
159159
// position is wrong for about 300ms, so we ignore updates during initial play.
160-
bool _listenToPositionStream = true;
161-
bool _usedToStartPlaying = false;
160+
// this value should be reset to null when audio is played to the end or when user drags.
161+
bool? _listenToPositionStream;
162162

163163
@override
164164
void initState() {
@@ -220,6 +220,8 @@ class _SpVoicePlayerState extends State<SpVoicePlayer> with WidgetsBindingObserv
220220
if (state.processingState == ProcessingState.completed) {
221221
player.pause();
222222
player.seek(Duration.zero);
223+
224+
_listenToPositionStream = null;
223225
}
224226
});
225227

@@ -290,12 +292,11 @@ class _SpVoicePlayerState extends State<SpVoicePlayer> with WidgetsBindingObserv
290292
if (playing) {
291293
player.pause();
292294
} else {
293-
if (Platform.isAndroid && !_usedToStartPlaying) {
295+
if (Platform.isAndroid && _listenToPositionStream == null) {
294296
_listenToPositionStream = false;
295297
Future.delayed(const Duration(milliseconds: 300), () => _listenToPositionStream = true);
296298
}
297299

298-
_usedToStartPlaying = true;
299300
player.play();
300301
}
301302
} catch (e) {
@@ -360,6 +361,7 @@ class _SpVoicePlayerState extends State<SpVoicePlayer> with WidgetsBindingObserv
360361
_isDragging = false;
361362

362363
try {
364+
_listenToPositionStream = null;
363365
await player.seek(_draggedPosition);
364366
} catch (e) {
365367
debugPrint('❌ Error seeking to position: $e');

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: storypad
2-
version: 2.20.0+502
2+
version: 2.20.0+504
33
publish_to: none
44
environment:
55
sdk: ^3.8.0

0 commit comments

Comments
 (0)