mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 18:57:25 +01:00
Make Backend a stateful widget
This commit is contained in:
parent
ad7499051b
commit
3f0567e688
5 changed files with 35 additions and 15 deletions
|
|
@ -15,7 +15,7 @@ class _AppState extends State<App> with SingleTickerProviderStateMixin {
|
||||||
final nestedNavigator = GlobalKey<NavigatorState>();
|
final nestedNavigator = GlobalKey<NavigatorState>();
|
||||||
|
|
||||||
AnimationController playerBarAnimation;
|
AnimationController playerBarAnimation;
|
||||||
Backend backend;
|
BackendState backend;
|
||||||
StreamSubscription<bool> playerActiveSubscription;
|
StreamSubscription<bool> playerActiveSubscription;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
||||||
|
|
@ -3,21 +3,34 @@ import 'package:rxdart/rxdart.dart';
|
||||||
|
|
||||||
import 'database.dart';
|
import 'database.dart';
|
||||||
|
|
||||||
class Backend extends InheritedWidget {
|
class Backend extends StatefulWidget {
|
||||||
static Backend of(BuildContext context) =>
|
|
||||||
context.dependOnInheritedWidgetOfExactType<Backend>();
|
|
||||||
|
|
||||||
final Widget child;
|
final Widget child;
|
||||||
|
|
||||||
|
Backend({
|
||||||
|
@required this.child,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
BackendState createState() => BackendState();
|
||||||
|
|
||||||
|
static BackendState of(BuildContext context) =>
|
||||||
|
context.dependOnInheritedWidgetOfExactType<_InheritedBackend>().state;
|
||||||
|
}
|
||||||
|
|
||||||
|
class BackendState extends State<Backend> {
|
||||||
final db = Database('musicus.sqlite');
|
final db = Database('musicus.sqlite');
|
||||||
|
|
||||||
final playerActive = BehaviorSubject.seeded(false);
|
final playerActive = BehaviorSubject.seeded(false);
|
||||||
final playing = BehaviorSubject.seeded(false);
|
final playing = BehaviorSubject.seeded(false);
|
||||||
final position = BehaviorSubject.seeded(0.0);
|
final position = BehaviorSubject.seeded(0.0);
|
||||||
|
|
||||||
Backend({
|
@override
|
||||||
@required this.child,
|
Widget build(BuildContext context) {
|
||||||
}) : super(child: child);
|
return _InheritedBackend(
|
||||||
|
child: widget.child,
|
||||||
|
state: this,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
void startPlayer() {
|
void startPlayer() {
|
||||||
playerActive.add(true);
|
playerActive.add(true);
|
||||||
|
|
@ -44,10 +57,17 @@ class Backend extends InheritedWidget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _InheritedBackend extends InheritedWidget {
|
||||||
|
final Widget child;
|
||||||
|
final BackendState state;
|
||||||
|
|
||||||
|
_InheritedBackend({
|
||||||
|
@required this.child,
|
||||||
|
@required this.state,
|
||||||
|
}) : super(child: child);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool updateShouldNotify(Backend old) =>
|
bool updateShouldNotify(_InheritedBackend old) => state != old.state;
|
||||||
playerActive != old.playerActive ||
|
|
||||||
playing != old.playing ||
|
|
||||||
position != old.position;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -209,7 +209,7 @@ class WorkEditor extends StatefulWidget {
|
||||||
class _WorkEditorState extends State<WorkEditor> {
|
class _WorkEditorState extends State<WorkEditor> {
|
||||||
final titleController = TextEditingController();
|
final titleController = TextEditingController();
|
||||||
|
|
||||||
Backend backend;
|
BackendState backend;
|
||||||
|
|
||||||
String title = '';
|
String title = '';
|
||||||
Person composer;
|
Person composer;
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ class ProgramScreen extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ProgramScreenState extends State<ProgramScreen> {
|
class _ProgramScreenState extends State<ProgramScreen> {
|
||||||
Backend backend;
|
BackendState backend;
|
||||||
StreamSubscription<double> positionSubscription;
|
StreamSubscription<double> positionSubscription;
|
||||||
double position = 0.0;
|
double position = 0.0;
|
||||||
bool seeking = false;
|
bool seeking = false;
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ class PlayPauseButton extends StatefulWidget {
|
||||||
class _PlayPauseButtonState extends State<PlayPauseButton>
|
class _PlayPauseButtonState extends State<PlayPauseButton>
|
||||||
with SingleTickerProviderStateMixin {
|
with SingleTickerProviderStateMixin {
|
||||||
AnimationController playPauseAnimation;
|
AnimationController playPauseAnimation;
|
||||||
Backend backend;
|
BackendState backend;
|
||||||
StreamSubscription<bool> playingSubscription;
|
StreamSubscription<bool> playingSubscription;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue