mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 18:57:25 +01:00
common: Fix recording editor initialization
This commit is contained in:
parent
19da47ea04
commit
7b63cc7aaf
1 changed files with 40 additions and 33 deletions
|
|
@ -25,30 +25,37 @@ class RecordingEditor extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _RecordingEditorState extends State<RecordingEditor> {
|
class _RecordingEditorState extends State<RecordingEditor> {
|
||||||
final commentController = TextEditingController();
|
final _commentController = TextEditingController();
|
||||||
|
|
||||||
bool uploading = false;
|
MusicusBackendState _backend;
|
||||||
WorkInfo workInfo;
|
bool _uploading = false;
|
||||||
List<PerformanceInfo> performanceInfos = [];
|
WorkInfo _workInfo;
|
||||||
|
List<PerformanceInfo> _performanceInfos = [];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void didChangeDependencies() {
|
||||||
super.initState();
|
super.didChangeDependencies();
|
||||||
|
|
||||||
if (widget.recordingInfo != null) {
|
_backend = MusicusBackend.of(context);
|
||||||
final backend = MusicusBackend.of(context);
|
if (widget.recordingInfo != null &&
|
||||||
|
_workInfo == null &&
|
||||||
() async {
|
_performanceInfos.isEmpty) {
|
||||||
workInfo = await backend.db.getWork(widget.recordingInfo.recording.id);
|
_init();
|
||||||
performanceInfos = List.from(widget.recordingInfo.performances);
|
|
||||||
}();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _init() async {
|
||||||
|
_workInfo = await _backend.db.getWork(widget.recordingInfo.recording.work);
|
||||||
|
_performanceInfos = List.from(widget.recordingInfo.performances);
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
this._workInfo = _workInfo;
|
||||||
|
this._performanceInfos = _performanceInfos;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final backend = MusicusBackend.of(context);
|
|
||||||
|
|
||||||
Future<void> selectWork() async {
|
Future<void> selectWork() async {
|
||||||
final WorkInfo newWorkInfo = await Navigator.push(
|
final WorkInfo newWorkInfo = await Navigator.push(
|
||||||
context,
|
context,
|
||||||
|
|
@ -59,14 +66,14 @@ class _RecordingEditorState extends State<RecordingEditor> {
|
||||||
|
|
||||||
if (newWorkInfo != null) {
|
if (newWorkInfo != null) {
|
||||||
setState(() {
|
setState(() {
|
||||||
workInfo = newWorkInfo;
|
_workInfo = newWorkInfo;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<Widget> performanceTiles = [];
|
final List<Widget> performanceTiles = [];
|
||||||
for (var i = 0; i < performanceInfos.length; i++) {
|
for (var i = 0; i < _performanceInfos.length; i++) {
|
||||||
final p = performanceInfos[i];
|
final p = _performanceInfos[i];
|
||||||
|
|
||||||
performanceTiles.add(ListTile(
|
performanceTiles.add(ListTile(
|
||||||
title: Text(p.person != null
|
title: Text(p.person != null
|
||||||
|
|
@ -77,7 +84,7 @@ class _RecordingEditorState extends State<RecordingEditor> {
|
||||||
icon: const Icon(Icons.delete),
|
icon: const Icon(Icons.delete),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
performanceInfos.remove(p);
|
_performanceInfos.remove(p);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
@ -93,7 +100,7 @@ class _RecordingEditorState extends State<RecordingEditor> {
|
||||||
|
|
||||||
if (performanceInfo != null) {
|
if (performanceInfo != null) {
|
||||||
setState(() {
|
setState(() {
|
||||||
performanceInfos[i] = performanceInfo;
|
_performanceInfos[i] = performanceInfo;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -104,7 +111,7 @@ class _RecordingEditorState extends State<RecordingEditor> {
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text('Recording'),
|
title: Text('Recording'),
|
||||||
actions: <Widget>[
|
actions: <Widget>[
|
||||||
uploading
|
_uploading
|
||||||
? Padding(
|
? Padding(
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.all(16.0),
|
||||||
child: Center(
|
child: Center(
|
||||||
|
|
@ -121,31 +128,31 @@ class _RecordingEditorState extends State<RecordingEditor> {
|
||||||
child: Text('DONE'),
|
child: Text('DONE'),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
setState(() {
|
setState(() {
|
||||||
uploading = true;
|
_uploading = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
final recordingInfo = RecordingInfo(
|
final recordingInfo = RecordingInfo(
|
||||||
recording: Recording(
|
recording: Recording(
|
||||||
id: widget?.recordingInfo?.recording?.id ??
|
id: widget?.recordingInfo?.recording?.id ??
|
||||||
generateId(),
|
generateId(),
|
||||||
work: workInfo.work.id,
|
work: _workInfo.work.id,
|
||||||
comment: commentController.text,
|
comment: _commentController.text,
|
||||||
),
|
),
|
||||||
performances: performanceInfos,
|
performances: _performanceInfos,
|
||||||
);
|
);
|
||||||
|
|
||||||
final success =
|
final success =
|
||||||
await backend.client.putRecording(recordingInfo);
|
await _backend.client.putRecording(recordingInfo);
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
uploading = false;
|
_uploading = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
Navigator.pop(
|
Navigator.pop(
|
||||||
context,
|
context,
|
||||||
RecordingSelectorResult(
|
RecordingSelectorResult(
|
||||||
workInfo: workInfo,
|
workInfo: _workInfo,
|
||||||
recordingInfo: recordingInfo,
|
recordingInfo: recordingInfo,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
@ -160,10 +167,10 @@ class _RecordingEditorState extends State<RecordingEditor> {
|
||||||
),
|
),
|
||||||
body: ListView(
|
body: ListView(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
workInfo != null
|
_workInfo != null
|
||||||
? ListTile(
|
? ListTile(
|
||||||
title: Text(workInfo.work.title),
|
title: Text(_workInfo.work.title),
|
||||||
subtitle: Text(workInfo.composers
|
subtitle: Text(_workInfo.composers
|
||||||
.map((p) => '${p.firstName} ${p.lastName}')
|
.map((p) => '${p.firstName} ${p.lastName}')
|
||||||
.join(', ')),
|
.join(', ')),
|
||||||
onTap: selectWork,
|
onTap: selectWork,
|
||||||
|
|
@ -181,7 +188,7 @@ class _RecordingEditorState extends State<RecordingEditor> {
|
||||||
bottom: 16.0,
|
bottom: 16.0,
|
||||||
),
|
),
|
||||||
child: TextField(
|
child: TextField(
|
||||||
controller: commentController,
|
controller: _commentController,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: 'Comment',
|
labelText: 'Comment',
|
||||||
),
|
),
|
||||||
|
|
@ -201,7 +208,7 @@ class _RecordingEditorState extends State<RecordingEditor> {
|
||||||
|
|
||||||
if (model != null) {
|
if (model != null) {
|
||||||
setState(() {
|
setState(() {
|
||||||
performanceInfos.add(model);
|
_performanceInfos.add(model);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue