From 9cc0b9020dd1dd3680eafe7a0bba84fd96f6e49c Mon Sep 17 00:00:00 2001 From: Elias Projahn Date: Sun, 22 Mar 2020 16:49:20 +0100 Subject: [PATCH] Add basic recording editor --- lib/editors/recording.dart | 144 +++++++++++++++++++++++++++++++++++++ lib/screens/home.dart | 6 +- 2 files changed, 147 insertions(+), 3 deletions(-) create mode 100644 lib/editors/recording.dart diff --git a/lib/editors/recording.dart b/lib/editors/recording.dart new file mode 100644 index 0000000..e3782f1 --- /dev/null +++ b/lib/editors/recording.dart @@ -0,0 +1,144 @@ +import 'package:flutter/material.dart'; + +import '../backend.dart'; +import '../database.dart'; +import '../selectors/performer.dart'; +import '../selectors/work.dart'; + +class RecordingEditor extends StatefulWidget { + final Recording recording; + + RecordingEditor({ + this.recording, + }); + + @override + _RecordingEditorState createState() => _RecordingEditorState(); +} + +class _RecordingEditorState extends State { + Work work; + List performances = []; + + @override + void initState() { + super.initState(); + + if (widget.recording != null) { + // TODO: Initialize. + } + } + + @override + Widget build(BuildContext context) { + final backend = Backend.of(context); + + Future selectWork() async { + final Work newWork = await Navigator.push( + context, + MaterialPageRoute( + builder: (context) => WorkSelector(), + fullscreenDialog: true, + )); + + if (newWork != null) { + setState(() { + work = newWork; + }); + } + } + + return Scaffold( + appBar: AppBar( + title: Text('Recording'), + actions: [ + FlatButton( + child: Text('DONE'), + onPressed: () async { + final recording = Recording( + id: widget.recording?.id ?? generateId(), + work: null, + ); + + await backend.db.updateRecording(recording, performances); + Navigator.pop(context, recording); + }, + ) + ], + ), + body: ListView( + children: [ + work != null + ? StreamBuilder>( + stream: backend.db.composersByWork(work.id).watch(), + builder: (context, snapshot) { + if (snapshot.hasData) { + return ListTile( + title: Text(work.title), + subtitle: Text(snapshot.data + .map((p) => '${p.firstName} ${p.lastName}') + .join(', ')), + onTap: selectWork, + ); + } else { + return ListTile( + title: Text(work.title), + subtitle: Text('…'), + onTap: selectWork, + ); + } + }, + ) + : ListTile( + title: Text('Work'), + subtitle: Text('Select work'), + onTap: selectWork, + ), + ListTile( + title: Text('Performers'), + trailing: IconButton( + icon: const Icon(Icons.add), + onPressed: () async { + final PerformanceModel model = await Navigator.push( + context, + MaterialPageRoute( + builder: (context) => PerformerSelector(), + fullscreenDialog: true, + )); + + if (model != null) { + setState(() { + performances.add(model); + }); + } + }, + ), + ), + for (final performance in performances) + ListTile( + title: Text(performance.person != null + ? '${performance.person.firstName} ${performance.person.lastName}' + : performance.ensemble.name), + subtitle: + performance.role != null ? Text(performance.role.name) : null, + trailing: IconButton( + icon: const Icon(Icons.delete), + onPressed: () { + setState(() { + performances.remove(performance); + }); + }, + ), + ), + ListTile( + title: Text('Tracks'), + trailing: IconButton( + icon: const Icon(Icons.add), + onPressed: () {}, + ), + ), + ], + ), + ); + } +} diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 795d3a8..d583e72 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import '../backend.dart'; import '../database.dart'; -import '../editors/work.dart'; +import '../editors/recording.dart'; import 'person.dart'; import 'settings.dart'; @@ -25,7 +25,7 @@ class HomeScreen extends StatelessWidget { ), PopupMenuItem( value: 1, - child: Text('Add work'), + child: Text('Add recording'), ), PopupMenuItem( value: 2, @@ -39,7 +39,7 @@ class HomeScreen extends StatelessWidget { Navigator.push( context, MaterialPageRoute( - builder: (context) => WorkEditor(), + builder: (context) => RecordingEditor(), fullscreenDialog: true, ), );