| 
									
										
										
										
											2019-12-03 12:47:23 +01:00
										 |  |  | import 'package:flutter/material.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import '../backend.dart'; | 
					
						
							|  |  |  | import '../database.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class InstrumentEditor extends StatefulWidget { | 
					
						
							|  |  |  |   final Instrument instrument; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   InstrumentEditor({ | 
					
						
							|  |  |  |     this.instrument, | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   _InstrumentEditorState createState() => _InstrumentEditorState(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class _InstrumentEditorState extends State<InstrumentEditor> { | 
					
						
							|  |  |  |   final nameController = TextEditingController(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   void initState() { | 
					
						
							|  |  |  |     super.initState(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (widget.instrument != null) { | 
					
						
							|  |  |  |       nameController.text = widget.instrument.name; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   Widget build(BuildContext context) { | 
					
						
							|  |  |  |     final backend = Backend.of(context); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return Scaffold( | 
					
						
							|  |  |  |       appBar: AppBar( | 
					
						
							| 
									
										
										
										
											2020-03-31 15:49:15 +02:00
										 |  |  |         title: Text('Instrument/Role'), | 
					
						
							| 
									
										
										
										
											2019-12-03 12:47:23 +01:00
										 |  |  |         actions: <Widget>[ | 
					
						
							|  |  |  |           FlatButton( | 
					
						
							|  |  |  |             child: Text('DONE'), | 
					
						
							|  |  |  |             onPressed: () async { | 
					
						
							|  |  |  |               final instrument = Instrument( | 
					
						
							|  |  |  |                 id: widget.instrument?.id ?? generateId(), | 
					
						
							|  |  |  |                 name: nameController.text, | 
					
						
							|  |  |  |               ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               await backend.db.updateInstrument(instrument); | 
					
						
							|  |  |  |               Navigator.pop(context, instrument); | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           ) | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |       body: ListView( | 
					
						
							|  |  |  |         children: <Widget>[ | 
					
						
							|  |  |  |           Padding( | 
					
						
							|  |  |  |             padding: const EdgeInsets.all(16.0), | 
					
						
							|  |  |  |             child: TextField( | 
					
						
							|  |  |  |               controller: nameController, | 
					
						
							|  |  |  |               decoration: InputDecoration( | 
					
						
							|  |  |  |                 labelText: 'Name', | 
					
						
							|  |  |  |               ), | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |