diff --git a/lib/app.dart b/lib/app.dart index a0670f0..cbb70bf 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -15,7 +15,7 @@ class _AppState extends State with SingleTickerProviderStateMixin { final nestedNavigator = GlobalKey(); AnimationController playerBarAnimation; - Backend backend; + BackendState backend; StreamSubscription playerActiveSubscription; @override diff --git a/lib/backend.dart b/lib/backend.dart index 3b00c0f..6fdfa69 100644 --- a/lib/backend.dart +++ b/lib/backend.dart @@ -3,21 +3,34 @@ import 'package:rxdart/rxdart.dart'; import 'database.dart'; -class Backend extends InheritedWidget { - static Backend of(BuildContext context) => - context.dependOnInheritedWidgetOfExactType(); - +class Backend extends StatefulWidget { final Widget child; + Backend({ + @required this.child, + }); + + @override + BackendState createState() => BackendState(); + + static BackendState of(BuildContext context) => + context.dependOnInheritedWidgetOfExactType<_InheritedBackend>().state; +} + +class BackendState extends State { final db = Database('musicus.sqlite'); final playerActive = BehaviorSubject.seeded(false); final playing = BehaviorSubject.seeded(false); final position = BehaviorSubject.seeded(0.0); - Backend({ - @required this.child, - }) : super(child: child); + @override + Widget build(BuildContext context) { + return _InheritedBackend( + child: widget.child, + state: this, + ); + } void startPlayer() { 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 - bool updateShouldNotify(Backend old) => - playerActive != old.playerActive || - playing != old.playing || - position != old.position; + bool updateShouldNotify(_InheritedBackend old) => state != old.state; } diff --git a/lib/editors/work.dart b/lib/editors/work.dart index 82559e7..523233f 100644 --- a/lib/editors/work.dart +++ b/lib/editors/work.dart @@ -209,7 +209,7 @@ class WorkEditor extends StatefulWidget { class _WorkEditorState extends State { final titleController = TextEditingController(); - Backend backend; + BackendState backend; String title = ''; Person composer; diff --git a/lib/screens/program.dart b/lib/screens/program.dart index 3520ea3..5eed825 100644 --- a/lib/screens/program.dart +++ b/lib/screens/program.dart @@ -11,7 +11,7 @@ class ProgramScreen extends StatefulWidget { } class _ProgramScreenState extends State { - Backend backend; + BackendState backend; StreamSubscription positionSubscription; double position = 0.0; bool seeking = false; diff --git a/lib/widgets/play_pause_button.dart b/lib/widgets/play_pause_button.dart index d0e6efd..84703d8 100644 --- a/lib/widgets/play_pause_button.dart +++ b/lib/widgets/play_pause_button.dart @@ -12,7 +12,7 @@ class PlayPauseButton extends StatefulWidget { class _PlayPauseButtonState extends State with SingleTickerProviderStateMixin { AnimationController playPauseAnimation; - Backend backend; + BackendState backend; StreamSubscription playingSubscription; @override