| 
									
										
										
										
											2020-03-22 15:35:56 +01:00
										 |  |  | import 'package:flutter/material.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import '../backend.dart'; | 
					
						
							|  |  |  | import '../database.dart'; | 
					
						
							| 
									
										
										
										
											2020-03-31 16:15:59 +02:00
										 |  |  | import '../editors/ensemble.dart'; | 
					
						
							| 
									
										
										
										
											2020-03-22 15:35:56 +01:00
										 |  |  | import '../editors/person.dart'; | 
					
						
							| 
									
										
										
										
											2020-03-31 15:49:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | import 'instruments.dart'; | 
					
						
							| 
									
										
										
										
											2020-03-22 15:35:56 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | class PerformerSelector extends StatefulWidget { | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   _PerformerSelectorState createState() => _PerformerSelectorState(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-31 16:15:59 +02:00
										 |  |  | class _Selection { | 
					
						
							|  |  |  |   final bool isPerson; | 
					
						
							|  |  |  |   final Person person; | 
					
						
							|  |  |  |   final Ensemble ensemble; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   _Selection.person(this.person) | 
					
						
							|  |  |  |       : isPerson = true, | 
					
						
							|  |  |  |         ensemble = null; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   _Selection.ensemble(this.ensemble) | 
					
						
							|  |  |  |       : isPerson = false, | 
					
						
							|  |  |  |         person = null; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-22 15:35:56 +01:00
										 |  |  | class _PerformerSelectorState extends State<PerformerSelector> { | 
					
						
							| 
									
										
										
										
											2020-03-31 15:49:15 +02:00
										 |  |  |   Instrument role; | 
					
						
							| 
									
										
										
										
											2020-03-31 16:15:59 +02:00
										 |  |  |   _Selection selection; | 
					
						
							| 
									
										
										
										
											2020-03-22 15:35:56 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   Widget build(BuildContext context) { | 
					
						
							|  |  |  |     final backend = Backend.of(context); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return Scaffold( | 
					
						
							|  |  |  |       appBar: AppBar( | 
					
						
							|  |  |  |         title: Text('Select performer'), | 
					
						
							| 
									
										
										
										
											2020-03-22 17:38:08 +01:00
										 |  |  |         actions: <Widget>[ | 
					
						
							|  |  |  |           FlatButton( | 
					
						
							|  |  |  |             child: Text('DONE'), | 
					
						
							|  |  |  |             onPressed: () => Navigator.pop( | 
					
						
							|  |  |  |               context, | 
					
						
							|  |  |  |               PerformanceModel( | 
					
						
							| 
									
										
										
										
											2020-03-31 16:15:59 +02:00
										 |  |  |                 person: selection?.person, | 
					
						
							|  |  |  |                 ensemble: selection?.ensemble, | 
					
						
							| 
									
										
										
										
											2020-03-22 17:38:08 +01:00
										 |  |  |                 role: role, | 
					
						
							|  |  |  |               ), | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  |         ], | 
					
						
							| 
									
										
										
										
											2020-03-22 15:35:56 +01:00
										 |  |  |       ), | 
					
						
							|  |  |  |       body: Column( | 
					
						
							|  |  |  |         children: <Widget>[ | 
					
						
							|  |  |  |           Material( | 
					
						
							|  |  |  |             elevation: 2.0, | 
					
						
							|  |  |  |             child: ListTile( | 
					
						
							| 
									
										
										
										
											2020-03-31 15:49:15 +02:00
										 |  |  |               title: Text('Instrument/Role'), | 
					
						
							| 
									
										
										
										
											2020-03-22 15:35:56 +01:00
										 |  |  |               subtitle: | 
					
						
							| 
									
										
										
										
											2020-03-31 15:49:15 +02:00
										 |  |  |                   Text(role != null ? role.name : 'Select instrument/role'), | 
					
						
							| 
									
										
										
										
											2020-03-22 15:35:56 +01:00
										 |  |  |               trailing: IconButton( | 
					
						
							|  |  |  |                 icon: const Icon(Icons.delete), | 
					
						
							|  |  |  |                 onPressed: () { | 
					
						
							|  |  |  |                   setState(() { | 
					
						
							|  |  |  |                     role = null; | 
					
						
							|  |  |  |                   }); | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |               ), | 
					
						
							|  |  |  |               onTap: () async { | 
					
						
							| 
									
										
										
										
											2020-03-31 15:49:15 +02:00
										 |  |  |                 final Instrument newRole = await Navigator.push( | 
					
						
							| 
									
										
										
										
											2020-03-22 15:35:56 +01:00
										 |  |  |                     context, | 
					
						
							|  |  |  |                     MaterialPageRoute( | 
					
						
							| 
									
										
										
										
											2020-03-31 15:49:15 +02:00
										 |  |  |                       builder: (context) => InstrumentsSelector(), | 
					
						
							| 
									
										
										
										
											2020-03-22 15:35:56 +01:00
										 |  |  |                       fullscreenDialog: true, | 
					
						
							|  |  |  |                     )); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if (newRole != null) { | 
					
						
							|  |  |  |                   setState(() { | 
					
						
							|  |  |  |                     role = newRole; | 
					
						
							|  |  |  |                   }); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |               }, | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  |           Expanded( | 
					
						
							| 
									
										
										
										
											2020-03-31 16:15:59 +02:00
										 |  |  |             child: ListView( | 
					
						
							|  |  |  |               children: <Widget>[ | 
					
						
							|  |  |  |                 StreamBuilder<List<Person>>( | 
					
						
							|  |  |  |                   stream: backend.db.allPersons().watch(), | 
					
						
							|  |  |  |                   builder: (context, snapshot) { | 
					
						
							|  |  |  |                     if (snapshot.hasData && snapshot.data.isNotEmpty) { | 
					
						
							|  |  |  |                       return ExpansionTile( | 
					
						
							|  |  |  |                         initiallyExpanded: true, | 
					
						
							|  |  |  |                         title: Text('Persons'), | 
					
						
							|  |  |  |                         children: snapshot.data | 
					
						
							|  |  |  |                             .map((person) => RadioListTile<Person>( | 
					
						
							|  |  |  |                                   title: Text( | 
					
						
							|  |  |  |                                       '${person.lastName}, ${person.firstName}'), | 
					
						
							|  |  |  |                                   value: person, | 
					
						
							|  |  |  |                                   groupValue: selection?.person, | 
					
						
							|  |  |  |                                   onChanged: (person) { | 
					
						
							|  |  |  |                                     setState(() { | 
					
						
							|  |  |  |                                       selection = _Selection.person(person); | 
					
						
							|  |  |  |                                     }); | 
					
						
							|  |  |  |                                   }, | 
					
						
							|  |  |  |                                 )) | 
					
						
							|  |  |  |                             .toList(), | 
					
						
							|  |  |  |                       ); | 
					
						
							|  |  |  |                     } else { | 
					
						
							|  |  |  |                       return Container(); | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                   }, | 
					
						
							|  |  |  |                 ), | 
					
						
							|  |  |  |                 StreamBuilder<List<Ensemble>>( | 
					
						
							|  |  |  |                   stream: backend.db.allEnsembles().watch(), | 
					
						
							|  |  |  |                   builder: (context, snapshot) { | 
					
						
							|  |  |  |                     if (snapshot.hasData && snapshot.data.isNotEmpty) { | 
					
						
							|  |  |  |                       return ExpansionTile( | 
					
						
							|  |  |  |                         initiallyExpanded: true, | 
					
						
							|  |  |  |                         title: Text('Ensembles'), | 
					
						
							|  |  |  |                         children: snapshot.data | 
					
						
							|  |  |  |                             .map((ensemble) => RadioListTile<Ensemble>( | 
					
						
							|  |  |  |                                   title: Text(ensemble.name), | 
					
						
							|  |  |  |                                   value: ensemble, | 
					
						
							|  |  |  |                                   groupValue: selection?.ensemble, | 
					
						
							|  |  |  |                                   onChanged: (ensemble) { | 
					
						
							|  |  |  |                                     setState(() { | 
					
						
							|  |  |  |                                       selection = _Selection.ensemble(ensemble); | 
					
						
							|  |  |  |                                     }); | 
					
						
							|  |  |  |                                   }, | 
					
						
							|  |  |  |                                 )) | 
					
						
							|  |  |  |                             .toList(), | 
					
						
							|  |  |  |                       ); | 
					
						
							|  |  |  |                     } else { | 
					
						
							|  |  |  |                       return Container(); | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                   }, | 
					
						
							|  |  |  |                 ), | 
					
						
							|  |  |  |               ], | 
					
						
							| 
									
										
										
										
											2020-03-22 15:35:56 +01:00
										 |  |  |             ), | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |       floatingActionButton: FloatingActionButton( | 
					
						
							|  |  |  |         child: const Icon(Icons.add), | 
					
						
							|  |  |  |         onPressed: () async { | 
					
						
							| 
									
										
										
										
											2020-03-31 16:15:59 +02:00
										 |  |  |           showModalBottomSheet( | 
					
						
							|  |  |  |             context: context, | 
					
						
							|  |  |  |             builder: (context) => Column( | 
					
						
							|  |  |  |               mainAxisSize: MainAxisSize.min, | 
					
						
							|  |  |  |               children: <Widget>[ | 
					
						
							|  |  |  |                 ListTile( | 
					
						
							|  |  |  |                   leading: const Icon(Icons.add), | 
					
						
							|  |  |  |                   title: Text('Add person'), | 
					
						
							|  |  |  |                   onTap: () async { | 
					
						
							|  |  |  |                     final Person person = await Navigator.push( | 
					
						
							|  |  |  |                         context, | 
					
						
							|  |  |  |                         MaterialPageRoute( | 
					
						
							|  |  |  |                           builder: (context) => PersonEditor(), | 
					
						
							|  |  |  |                           fullscreenDialog: true, | 
					
						
							|  |  |  |                         )); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     if (person != null) { | 
					
						
							|  |  |  |                       setState(() { | 
					
						
							|  |  |  |                         selection = _Selection.person(person); | 
					
						
							|  |  |  |                       }); | 
					
						
							|  |  |  |                     } | 
					
						
							| 
									
										
										
										
											2020-03-22 15:35:56 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-31 16:15:59 +02:00
										 |  |  |                     Navigator.pop(context); | 
					
						
							|  |  |  |                   }, | 
					
						
							|  |  |  |                 ), | 
					
						
							|  |  |  |                 ListTile( | 
					
						
							|  |  |  |                   leading: const Icon(Icons.add), | 
					
						
							|  |  |  |                   title: Text('Add ensemble'), | 
					
						
							|  |  |  |                   onTap: () async { | 
					
						
							|  |  |  |                     final Ensemble ensemble = await Navigator.push( | 
					
						
							|  |  |  |                         context, | 
					
						
							|  |  |  |                         MaterialPageRoute( | 
					
						
							|  |  |  |                           builder: (context) => EnsembleEditor(), | 
					
						
							|  |  |  |                           fullscreenDialog: true, | 
					
						
							|  |  |  |                         )); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     if (ensemble != null) { | 
					
						
							|  |  |  |                       setState(() { | 
					
						
							|  |  |  |                         selection = _Selection.ensemble(ensemble); | 
					
						
							|  |  |  |                       }); | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     Navigator.pop(context); | 
					
						
							|  |  |  |                   }, | 
					
						
							|  |  |  |                 ), | 
					
						
							|  |  |  |               ], | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |           ); | 
					
						
							| 
									
										
										
										
											2020-03-22 15:35:56 +01:00
										 |  |  |         }, | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |