| 
									
										
										
										
											2020-03-22 16:49:20 +01:00
										 |  |  | import 'package:flutter/material.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import '../backend.dart'; | 
					
						
							|  |  |  | import '../database.dart'; | 
					
						
							|  |  |  | import '../selectors/performer.dart'; | 
					
						
							|  |  |  | import '../selectors/work.dart'; | 
					
						
							| 
									
										
										
										
											2020-04-06 11:29:55 +02:00
										 |  |  | import '../widgets/texts.dart'; | 
					
						
							| 
									
										
										
										
											2020-03-22 16:49:20 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | class RecordingEditor extends StatefulWidget { | 
					
						
							|  |  |  |   final Recording recording; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   RecordingEditor({ | 
					
						
							|  |  |  |     this.recording, | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   _RecordingEditorState createState() => _RecordingEditorState(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class _RecordingEditorState extends State<RecordingEditor> { | 
					
						
							| 
									
										
										
										
											2020-04-12 11:50:32 +02:00
										 |  |  |   final commentController = TextEditingController(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-22 16:49:20 +01:00
										 |  |  |   Work work; | 
					
						
							|  |  |  |   List<PerformanceModel> performances = []; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   void initState() { | 
					
						
							|  |  |  |     super.initState(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (widget.recording != null) { | 
					
						
							|  |  |  |       // TODO: Initialize.
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   Widget build(BuildContext context) { | 
					
						
							|  |  |  |     final backend = Backend.of(context); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Future<void> 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: <Widget>[ | 
					
						
							|  |  |  |           FlatButton( | 
					
						
							|  |  |  |             child: Text('DONE'), | 
					
						
							|  |  |  |             onPressed: () async { | 
					
						
							|  |  |  |               final recording = Recording( | 
					
						
							|  |  |  |                 id: widget.recording?.id ?? generateId(), | 
					
						
							| 
									
										
										
										
											2020-04-05 13:02:12 +02:00
										 |  |  |                 work: work.id, | 
					
						
							| 
									
										
										
										
											2020-04-12 11:50:32 +02:00
										 |  |  |                 comment: commentController.text, | 
					
						
							| 
									
										
										
										
											2020-03-22 16:49:20 +01:00
										 |  |  |               ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               await backend.db.updateRecording(recording, performances); | 
					
						
							|  |  |  |               Navigator.pop(context, recording); | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           ) | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |       body: ListView( | 
					
						
							|  |  |  |         children: <Widget>[ | 
					
						
							|  |  |  |           work != null | 
					
						
							| 
									
										
										
										
											2020-04-06 11:29:55 +02:00
										 |  |  |               ? ListTile( | 
					
						
							|  |  |  |                 title: WorkText(work.id), | 
					
						
							|  |  |  |                 subtitle: ComposersText(work.id), | 
					
						
							| 
									
										
										
										
											2020-04-12 11:51:13 +02:00
										 |  |  |                 onTap: selectWork, | 
					
						
							| 
									
										
										
										
											2020-04-06 11:29:55 +02:00
										 |  |  |               ) | 
					
						
							| 
									
										
										
										
											2020-03-22 16:49:20 +01:00
										 |  |  |               : ListTile( | 
					
						
							|  |  |  |                   title: Text('Work'), | 
					
						
							|  |  |  |                   subtitle: Text('Select work'), | 
					
						
							|  |  |  |                   onTap: selectWork, | 
					
						
							|  |  |  |                 ), | 
					
						
							| 
									
										
										
										
											2020-04-12 11:50:32 +02:00
										 |  |  |           Padding( | 
					
						
							|  |  |  |             padding: const EdgeInsets.only( | 
					
						
							|  |  |  |               left: 16.0, | 
					
						
							|  |  |  |               right: 16.0, | 
					
						
							|  |  |  |               top: 0.0, | 
					
						
							|  |  |  |               bottom: 16.0, | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |             child: TextField( | 
					
						
							|  |  |  |               controller: commentController, | 
					
						
							|  |  |  |               decoration: InputDecoration( | 
					
						
							|  |  |  |                 labelText: 'Comment', | 
					
						
							|  |  |  |               ), | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |           ), | 
					
						
							| 
									
										
										
										
											2020-03-22 16:49:20 +01:00
										 |  |  |           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); | 
					
						
							|  |  |  |                   }); | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |               ), | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |