From 40acc2b55514ab43214fc6df1a3c94a6be6a53cb Mon Sep 17 00:00:00 2001 From: Elias Projahn Date: Wed, 11 Dec 2019 13:19:56 +0100 Subject: [PATCH] Add initial selection to instrument selector Also use this from the work editor. --- lib/editors/work.dart | 4 +++- lib/selectors/instruments.dart | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/editors/work.dart b/lib/editors/work.dart index 909faef..fe09ebd 100644 --- a/lib/editors/work.dart +++ b/lib/editors/work.dart @@ -119,7 +119,9 @@ class _WorkEditorState extends State { final List selection = await Navigator.push( context, MaterialPageRoute( - builder: (context) => InstrumentsSelector(), + builder: (context) => InstrumentsSelector( + selection: instruments, + ), fullscreenDialog: true, )); diff --git a/lib/selectors/instruments.dart b/lib/selectors/instruments.dart index 84508cb..eb960bf 100644 --- a/lib/selectors/instruments.dart +++ b/lib/selectors/instruments.dart @@ -5,6 +5,12 @@ import '../database.dart'; import '../editors/instrument.dart'; class InstrumentsSelector extends StatefulWidget { + final List selection; + + InstrumentsSelector({ + this.selection, + }); + @override _InstrumentsSelectorState createState() => _InstrumentsSelectorState(); } @@ -12,6 +18,15 @@ class InstrumentsSelector extends StatefulWidget { class _InstrumentsSelectorState extends State { Set selection = {}; + @override + void initState() { + super.initState(); + + if (widget.selection != null) { + selection = widget.selection.toSet(); + } + } + @override Widget build(BuildContext context) { final backend = Backend.of(context); @@ -65,7 +80,7 @@ class _InstrumentsSelectorState extends State { builder: (context) => InstrumentEditor(), fullscreenDialog: true, )); - + if (instrument != null) { setState(() { selection.add(instrument);