mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 18:57:25 +01:00
Add playback position slider to program screen
ProgramScreen became a StatefulWidget. It listens to playback position updates from the backend and updates the slider unless the user is currently interacting with it.
This commit is contained in:
parent
17f3040645
commit
2beccd070a
1 changed files with 62 additions and 1 deletions
|
|
@ -1,6 +1,39 @@
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class ProgramScreen extends StatelessWidget {
|
import '../backend.dart';
|
||||||
|
|
||||||
|
class ProgramScreen extends StatefulWidget {
|
||||||
|
@override
|
||||||
|
_ProgramScreenState createState() => _ProgramScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ProgramScreenState extends State<ProgramScreen> {
|
||||||
|
Backend backend;
|
||||||
|
StreamSubscription<double> positionSubscription;
|
||||||
|
double position = 0.0;
|
||||||
|
bool seeking = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didChangeDependencies() {
|
||||||
|
super.didChangeDependencies();
|
||||||
|
|
||||||
|
backend = Backend.of(context);
|
||||||
|
|
||||||
|
if (positionSubscription != null) {
|
||||||
|
positionSubscription.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
positionSubscription = backend.position.listen((pos) {
|
||||||
|
if (!seeking) {
|
||||||
|
setState(() {
|
||||||
|
position = pos;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
|
@ -11,6 +44,34 @@ class ProgramScreen extends StatelessWidget {
|
||||||
),
|
),
|
||||||
title: Text('Program'),
|
title: Text('Program'),
|
||||||
),
|
),
|
||||||
|
bottomNavigationBar: BottomAppBar(
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: <Widget>[
|
||||||
|
Slider(
|
||||||
|
value: position,
|
||||||
|
onChangeStart: (_) {
|
||||||
|
seeking = true;
|
||||||
|
},
|
||||||
|
onChangeEnd: (pos) {
|
||||||
|
seeking = false;
|
||||||
|
backend.seekTo(pos);
|
||||||
|
},
|
||||||
|
onChanged: (pos) {
|
||||||
|
setState(() {
|
||||||
|
position = pos;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
super.dispose();
|
||||||
|
positionSubscription.cancel();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue