mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 18:57:25 +01:00
Add instrument selector to work editor
This commit is contained in:
parent
45c430e7f6
commit
4855cafdf3
1 changed files with 43 additions and 7 deletions
|
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../backend.dart';
|
import '../backend.dart';
|
||||||
import '../database.dart';
|
import '../database.dart';
|
||||||
|
import '../selectors/instruments.dart';
|
||||||
import '../selectors/person.dart';
|
import '../selectors/person.dart';
|
||||||
|
|
||||||
class WorkEditor extends StatefulWidget {
|
class WorkEditor extends StatefulWidget {
|
||||||
|
|
@ -20,6 +21,7 @@ class _WorkEditorState extends State<WorkEditor> {
|
||||||
|
|
||||||
Backend backend;
|
Backend backend;
|
||||||
Person composer;
|
Person composer;
|
||||||
|
List<Instrument> instruments = [];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
|
@ -36,7 +38,8 @@ class _WorkEditorState extends State<WorkEditor> {
|
||||||
|
|
||||||
backend = Backend.of(context);
|
backend = Backend.of(context);
|
||||||
|
|
||||||
if (widget.work != null && widget.work.composer != null) {
|
if (widget.work != null) {
|
||||||
|
if (widget.work.composer != null) {
|
||||||
() async {
|
() async {
|
||||||
final person =
|
final person =
|
||||||
await backend.db.personById(widget.work.composer).getSingle();
|
await backend.db.personById(widget.work.composer).getSingle();
|
||||||
|
|
@ -49,6 +52,19 @@ class _WorkEditorState extends State<WorkEditor> {
|
||||||
}
|
}
|
||||||
}();
|
}();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
() async {
|
||||||
|
final selection =
|
||||||
|
await backend.db.instrumentsByWork(widget.work.id).get();
|
||||||
|
|
||||||
|
// We don't want to override already selected instruments.
|
||||||
|
if (instruments.isEmpty) {
|
||||||
|
setState(() {
|
||||||
|
instruments = selection;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -94,6 +110,26 @@ class _WorkEditorState extends State<WorkEditor> {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
ListTile(
|
||||||
|
title: Text('Instruments'),
|
||||||
|
subtitle: Text(instruments.isNotEmpty
|
||||||
|
? instruments.map((i) => i.name).join(', ')
|
||||||
|
: 'Select instruments'),
|
||||||
|
onTap: () async {
|
||||||
|
final List<Instrument> selection = await Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => InstrumentsSelector(),
|
||||||
|
fullscreenDialog: true,
|
||||||
|
));
|
||||||
|
|
||||||
|
if (selection != null) {
|
||||||
|
setState(() {
|
||||||
|
instruments = selection;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue