mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 18:57:25 +01:00
Load the database asynchronously
Now the backend has multiple states including loading and the toplevel app widget was adapted accordingly.
This commit is contained in:
parent
3f0567e688
commit
87582f200d
2 changed files with 82 additions and 43 deletions
|
|
@ -3,6 +3,11 @@ import 'package:rxdart/rxdart.dart';
|
|||
|
||||
import 'database.dart';
|
||||
|
||||
enum BackendStatus {
|
||||
loading,
|
||||
ready,
|
||||
}
|
||||
|
||||
class Backend extends StatefulWidget {
|
||||
final Widget child;
|
||||
|
||||
|
|
@ -18,12 +23,19 @@ class Backend extends StatefulWidget {
|
|||
}
|
||||
|
||||
class BackendState extends State<Backend> {
|
||||
final db = Database('musicus.sqlite');
|
||||
|
||||
final playerActive = BehaviorSubject.seeded(false);
|
||||
final playing = BehaviorSubject.seeded(false);
|
||||
final position = BehaviorSubject.seeded(0.0);
|
||||
|
||||
Database db;
|
||||
BackendStatus status = BackendStatus.loading;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_load();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return _InheritedBackend(
|
||||
|
|
@ -32,6 +44,14 @@ class BackendState extends State<Backend> {
|
|||
);
|
||||
}
|
||||
|
||||
Future<void> _load() async {
|
||||
db = Database('musicus.sqlite');
|
||||
|
||||
setState(() {
|
||||
status = BackendStatus.ready;
|
||||
});
|
||||
}
|
||||
|
||||
void startPlayer() {
|
||||
playerActive.add(true);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue