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/instruments.dart';
|
||||||
import '../selectors/person.dart';
|
import '../selectors/person.dart';
|
||||||
|
|
||||||
class WorkEditor extends StatefulWidget {
|
class WorkData {
|
||||||
final Work work;
|
String title = '';
|
||||||
|
|
||||||
WorkEditor({
|
|
||||||
this.work,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
_WorkEditorState createState() => _WorkEditorState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _WorkEditorState extends State<WorkEditor> {
|
|
||||||
final titleController = TextEditingController();
|
|
||||||
|
|
||||||
Backend backend;
|
|
||||||
Person composer;
|
Person composer;
|
||||||
List<Instrument> instruments = [];
|
List<Instrument> instruments = [];
|
||||||
|
List<WorkData> parts = [];
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
|
|
||||||
if (widget.work != null) {
|
|
||||||
titleController.text = widget.work.title;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
class WorkProperties extends StatelessWidget {
|
||||||
void didChangeDependencies() {
|
final TextEditingController titleController;
|
||||||
super.didChangeDependencies();
|
final Person composer;
|
||||||
|
final List<Instrument> instruments;
|
||||||
|
final void Function(Person) onComposerChanged;
|
||||||
|
final void Function(List<Instrument>) onInstrumentsChanged;
|
||||||
|
|
||||||
backend = Backend.of(context);
|
WorkProperties({
|
||||||
|
@required this.titleController,
|
||||||
if (widget.work != null) {
|
@required this.composer,
|
||||||
if (widget.work.composer != null) {
|
@required this.instruments,
|
||||||
() async {
|
@required this.onComposerChanged,
|
||||||
final person =
|
@required this.onInstrumentsChanged,
|
||||||
await backend.db.personById(widget.work.composer).getSingle();
|
|
||||||
|
|
||||||
// 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(() {
|
|
||||||
instruments = selection;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Column(
|
||||||
appBar: AppBar(
|
|
||||||
title: Text('Work'),
|
|
||||||
actions: <Widget>[
|
|
||||||
FlatButton(
|
|
||||||
child: Text('DONE'),
|
|
||||||
onPressed: () {},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
body: ListView(
|
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.all(16.0),
|
||||||
|
|
@ -104,9 +54,7 @@ class _WorkEditorState extends State<WorkEditor> {
|
||||||
));
|
));
|
||||||
|
|
||||||
if (person != null) {
|
if (person != null) {
|
||||||
setState(() {
|
onComposerChanged(person);
|
||||||
composer = person;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
@ -126,10 +74,103 @@ class _WorkEditorState extends State<WorkEditor> {
|
||||||
));
|
));
|
||||||
|
|
||||||
if (selection != null) {
|
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(() {
|
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