mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 18:57:25 +01:00
Make work editor modular
The work editor holds all data for a work and its parts. The widgets for editing work information are reusable now.
This commit is contained in:
parent
0d29a5f15d
commit
0594b00199
1 changed files with 95 additions and 54 deletions
|
|
@ -5,81 +5,31 @@ import '../database.dart';
|
|||
import '../selectors/instruments.dart';
|
||||
import '../selectors/person.dart';
|
||||
|
||||
class WorkEditor extends StatefulWidget {
|
||||
final Work work;
|
||||
|
||||
WorkEditor({
|
||||
this.work,
|
||||
});
|
||||
|
||||
@override
|
||||
_WorkEditorState createState() => _WorkEditorState();
|
||||
}
|
||||
|
||||
class _WorkEditorState extends State<WorkEditor> {
|
||||
final titleController = TextEditingController();
|
||||
|
||||
Backend backend;
|
||||
class WorkData {
|
||||
String title = '';
|
||||
Person composer;
|
||||
List<Instrument> instruments = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
if (widget.work != null) {
|
||||
titleController.text = widget.work.title;
|
||||
}
|
||||
List<WorkData> parts = [];
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
class WorkProperties extends StatelessWidget {
|
||||
final TextEditingController titleController;
|
||||
final Person composer;
|
||||
final List<Instrument> instruments;
|
||||
final void Function(Person) onComposerChanged;
|
||||
final void Function(List<Instrument>) onInstrumentsChanged;
|
||||
|
||||
backend = Backend.of(context);
|
||||
|
||||
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) {
|
||||
setState(() {
|
||||
composer = person;
|
||||
WorkProperties({
|
||||
@required this.titleController,
|
||||
@required this.composer,
|
||||
@required this.instruments,
|
||||
@required this.onComposerChanged,
|
||||
@required this.onInstrumentsChanged,
|
||||
});
|
||||
}
|
||||
}();
|
||||
}
|
||||
|
||||
() 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
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Work'),
|
||||
actions: <Widget>[
|
||||
FlatButton(
|
||||
child: Text('DONE'),
|
||||
onPressed: () {},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: ListView(
|
||||
return Column(
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
|
|
@ -104,9 +54,7 @@ class _WorkEditorState extends State<WorkEditor> {
|
|||
));
|
||||
|
||||
if (person != null) {
|
||||
setState(() {
|
||||
composer = person;
|
||||
});
|
||||
onComposerChanged(person);
|
||||
}
|
||||
},
|
||||
),
|
||||
|
|
@ -126,10 +74,103 @@ class _WorkEditorState extends State<WorkEditor> {
|
|||
));
|
||||
|
||||
if (selection != null) {
|
||||
onInstrumentsChanged(selection);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class WorkEditor extends StatefulWidget {
|
||||
final Work work;
|
||||
|
||||
WorkEditor({
|
||||
this.work,
|
||||
});
|
||||
|
||||
@override
|
||||
_WorkEditorState createState() => _WorkEditorState();
|
||||
}
|
||||
|
||||
class _WorkEditorState extends State<WorkEditor> {
|
||||
final titleController = TextEditingController();
|
||||
|
||||
Backend backend;
|
||||
final WorkData data = WorkData();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
if (widget.work != null) {
|
||||
titleController.text = widget.work.title;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
|
||||
backend = Backend.of(context);
|
||||
|
||||
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 (data.composer != null) {
|
||||
setState(() {
|
||||
instruments = selection;
|
||||
data.composer = person;
|
||||
});
|
||||
}
|
||||
}();
|
||||
}
|
||||
|
||||
() async {
|
||||
final selection =
|
||||
await backend.db.instrumentsByWork(widget.work.id).get();
|
||||
|
||||
// We don't want to override already selected instruments.
|
||||
if (data.instruments.isEmpty) {
|
||||
setState(() {
|
||||
data.instruments = selection;
|
||||
});
|
||||
}
|
||||
}();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Work'),
|
||||
actions: <Widget>[
|
||||
FlatButton(
|
||||
child: Text('DONE'),
|
||||
onPressed: () {},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: ListView(
|
||||
children: <Widget>[
|
||||
WorkProperties(
|
||||
titleController: titleController,
|
||||
composer: data.composer,
|
||||
instruments: data.instruments,
|
||||
onComposerChanged: (composer) {
|
||||
setState(() {
|
||||
data.composer = composer;
|
||||
});
|
||||
},
|
||||
onInstrumentsChanged: (instruments) {
|
||||
setState(() {
|
||||
data.instruments = instruments;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue