mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 18:57:25 +01:00
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.
77 lines
1.7 KiB
Dart
77 lines
1.7 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
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
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
leading: IconButton(
|
|
icon: const Icon(Icons.keyboard_arrow_down),
|
|
onPressed: () => Navigator.pop(context),
|
|
),
|
|
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();
|
|
}
|
|
}
|