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 '../database.dart';
|
||||
import '../selectors/instruments.dart';
|
||||
import '../selectors/person.dart';
|
||||
|
||||
class WorkEditor extends StatefulWidget {
|
||||
|
|
@ -20,6 +21,7 @@ class _WorkEditorState extends State<WorkEditor> {
|
|||
|
||||
Backend backend;
|
||||
Person composer;
|
||||
List<Instrument> instruments = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
|
|
@ -36,15 +38,29 @@ class _WorkEditorState extends State<WorkEditor> {
|
|||
|
||||
backend = Backend.of(context);
|
||||
|
||||
if (widget.work != null && widget.work.composer != null) {
|
||||
() async {
|
||||
final person =
|
||||
await backend.db.personById(widget.work.composer).getSingle();
|
||||
if (widget.work != null) {
|
||||
if (widget.work.composer != null) {
|
||||
() async {
|
||||
final person =
|
||||
await backend.db.personById(widget.work.composer).getSingle();
|
||||
|
||||
// We don't want to override a newly selected composer.
|
||||
if (composer != null) {
|
||||
// We don't want to override a newly selected composer.
|
||||
if (composer != null) {
|
||||
setState(() {
|
||||
composer = person;
|
||||
});
|
||||
}
|
||||
}();
|
||||
}
|
||||
|
||||
() async {
|
||||
final selection =
|
||||
await backend.db.instrumentsByWork(widget.work.id).get();
|
||||
|
||||
// We don't want to override already selected instruments.
|
||||
if (instruments.isEmpty) {
|
||||
setState(() {
|
||||
composer = person;
|
||||
instruments = selection;
|
||||
});
|
||||
}
|
||||
}();
|
||||
|
|
@ -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