| 
									
										
										
										
											2020-03-22 15:35:56 +01:00
										 |  |  | import 'package:flutter/material.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import '../backend.dart'; | 
					
						
							|  |  |  | import '../database.dart'; | 
					
						
							|  |  |  | import '../editors/person.dart'; | 
					
						
							| 
									
										
										
										
											2020-03-31 15:49:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | import 'instruments.dart'; | 
					
						
							| 
									
										
										
										
											2020-03-22 15:35:56 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | // TODO: Allow selecting and adding ensembles.
 | 
					
						
							|  |  |  | class PerformerSelector extends StatefulWidget { | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   _PerformerSelectorState createState() => _PerformerSelectorState(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class _PerformerSelectorState extends State<PerformerSelector> { | 
					
						
							| 
									
										
										
										
											2020-03-31 15:49:15 +02:00
										 |  |  |   Instrument role; | 
					
						
							| 
									
										
										
										
											2020-03-22 17:38:08 +01:00
										 |  |  |   Person person; | 
					
						
							| 
									
										
										
										
											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( | 
					
						
							|  |  |  |                 person: person, | 
					
						
							|  |  |  |                 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( | 
					
						
							|  |  |  |             child: StreamBuilder( | 
					
						
							|  |  |  |               stream: backend.db.allPersons().watch(), | 
					
						
							|  |  |  |               builder: (context, snapshot) { | 
					
						
							|  |  |  |                 if (snapshot.hasData) { | 
					
						
							|  |  |  |                   return ListView.builder( | 
					
						
							|  |  |  |                     itemCount: snapshot.data.length, | 
					
						
							|  |  |  |                     itemBuilder: (context, index) { | 
					
						
							|  |  |  |                       final person = snapshot.data[index]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-22 17:38:08 +01:00
										 |  |  |                       return RadioListTile<Person>( | 
					
						
							|  |  |  |                           controlAffinity: ListTileControlAffinity.trailing, | 
					
						
							|  |  |  |                           title: | 
					
						
							|  |  |  |                               Text('${person.lastName}, ${person.firstName}'), | 
					
						
							|  |  |  |                           value: person, | 
					
						
							|  |  |  |                           groupValue: this.person, | 
					
						
							|  |  |  |                           onChanged: (newPerson) { | 
					
						
							|  |  |  |                             setState(() { | 
					
						
							|  |  |  |                               this.person = newPerson; | 
					
						
							|  |  |  |                             }); | 
					
						
							|  |  |  |                           }); | 
					
						
							| 
									
										
										
										
											2020-03-22 15:35:56 +01:00
										 |  |  |                     }, | 
					
						
							|  |  |  |                   ); | 
					
						
							|  |  |  |                 } else { | 
					
						
							|  |  |  |                   return Container(); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |               }, | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |       floatingActionButton: FloatingActionButton( | 
					
						
							|  |  |  |         child: const Icon(Icons.add), | 
					
						
							|  |  |  |         onPressed: () async { | 
					
						
							|  |  |  |           final Person person = await Navigator.push( | 
					
						
							|  |  |  |               context, | 
					
						
							|  |  |  |               MaterialPageRoute( | 
					
						
							|  |  |  |                 builder: (context) => PersonEditor(), | 
					
						
							|  |  |  |                 fullscreenDialog: true, | 
					
						
							|  |  |  |               )); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           if (person != null) { | 
					
						
							| 
									
										
										
										
											2020-03-22 17:38:08 +01:00
										 |  |  |             setState(() { | 
					
						
							|  |  |  |               this.person = person; | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2020-03-22 15:35:56 +01:00
										 |  |  |           } | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |