| 
									
										
										
										
											2019-12-02 21:05:49 +01:00
										 |  |  | import 'package:flutter/material.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import '../backend.dart'; | 
					
						
							| 
									
										
										
										
											2019-12-15 12:16:08 +01:00
										 |  |  | import '../database.dart'; | 
					
						
							| 
									
										
										
										
											2020-04-06 11:43:46 +02:00
										 |  |  | import '../editors/tracks.dart'; | 
					
						
							| 
									
										
										
										
											2020-03-21 17:46:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-15 12:22:39 +01:00
										 |  |  | import 'person.dart'; | 
					
						
							| 
									
										
										
										
											2020-03-21 17:46:23 +01:00
										 |  |  | import 'settings.dart'; | 
					
						
							| 
									
										
										
										
											2019-12-02 21:05:49 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | class HomeScreen extends StatelessWidget { | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   Widget build(BuildContext context) { | 
					
						
							|  |  |  |     final backend = Backend.of(context); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return Scaffold( | 
					
						
							|  |  |  |       appBar: AppBar( | 
					
						
							|  |  |  |         title: Text('Musicus'), | 
					
						
							| 
									
										
										
										
											2019-12-15 12:11:40 +01:00
										 |  |  |         actions: <Widget>[ | 
					
						
							|  |  |  |           PopupMenuButton( | 
					
						
							|  |  |  |             icon: const Icon(Icons.more_vert), | 
					
						
							|  |  |  |             itemBuilder: (context) => [ | 
					
						
							|  |  |  |               PopupMenuItem( | 
					
						
							|  |  |  |                 value: 0, | 
					
						
							|  |  |  |                 child: Text('Start player'), | 
					
						
							|  |  |  |               ), | 
					
						
							|  |  |  |               PopupMenuItem( | 
					
						
							|  |  |  |                 value: 1, | 
					
						
							| 
									
										
										
										
											2020-04-06 11:43:46 +02:00
										 |  |  |                 child: Text('Add tracks'), | 
					
						
							| 
									
										
										
										
											2019-12-15 12:11:40 +01:00
										 |  |  |               ), | 
					
						
							| 
									
										
										
										
											2020-03-21 17:46:23 +01:00
										 |  |  |               PopupMenuItem( | 
					
						
							|  |  |  |                 value: 2, | 
					
						
							|  |  |  |                 child: Text('Settings'), | 
					
						
							|  |  |  |               ), | 
					
						
							| 
									
										
										
										
											2019-12-15 12:11:40 +01:00
										 |  |  |             ], | 
					
						
							|  |  |  |             onSelected: (selected) { | 
					
						
							|  |  |  |               if (selected == 0) { | 
					
						
							| 
									
										
										
										
											2020-04-18 13:50:38 +02:00
										 |  |  |                 backend.player.start(); | 
					
						
							| 
									
										
										
										
											2019-12-15 12:11:40 +01:00
										 |  |  |               } else if (selected == 1) { | 
					
						
							|  |  |  |                 Navigator.push( | 
					
						
							|  |  |  |                   context, | 
					
						
							|  |  |  |                   MaterialPageRoute( | 
					
						
							| 
									
										
										
										
											2020-04-06 11:43:46 +02:00
										 |  |  |                     builder: (context) => TracksEditor(), | 
					
						
							|  |  |  |                     fullscreenDialog: true, | 
					
						
							| 
									
										
										
										
											2019-12-15 12:11:40 +01:00
										 |  |  |                   ), | 
					
						
							|  |  |  |                 ); | 
					
						
							| 
									
										
										
										
											2020-03-21 17:46:23 +01:00
										 |  |  |               } else if (selected == 2) { | 
					
						
							|  |  |  |                 Navigator.push( | 
					
						
							|  |  |  |                   context, | 
					
						
							|  |  |  |                   MaterialPageRoute( | 
					
						
							|  |  |  |                     builder: (context) => SettingsScreen(), | 
					
						
							|  |  |  |                   ), | 
					
						
							|  |  |  |                 ); | 
					
						
							| 
									
										
										
										
											2019-12-15 12:11:40 +01:00
										 |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2019-12-11 13:07:46 +01:00
										 |  |  |           ), | 
					
						
							| 
									
										
										
										
											2019-12-02 21:05:49 +01:00
										 |  |  |         ], | 
					
						
							|  |  |  |       ), | 
					
						
							| 
									
										
										
										
											2019-12-15 12:11:40 +01:00
										 |  |  |       // For debugging purposes
 | 
					
						
							| 
									
										
										
										
											2019-12-15 12:16:08 +01:00
										 |  |  |       body: StreamBuilder<List<Person>>( | 
					
						
							|  |  |  |         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]; | 
					
						
							|  |  |  |                 return ListTile( | 
					
						
							|  |  |  |                   title: Text('${person.lastName}, ${person.firstName}'), | 
					
						
							| 
									
										
										
										
											2019-12-15 12:22:39 +01:00
										 |  |  |                   onTap: () => Navigator.push( | 
					
						
							|  |  |  |                     context, | 
					
						
							|  |  |  |                     MaterialPageRoute( | 
					
						
							|  |  |  |                       builder: (context) => PersonScreen( | 
					
						
							|  |  |  |                         person: person, | 
					
						
							|  |  |  |                       ), | 
					
						
							|  |  |  |                     ), | 
					
						
							|  |  |  |                   ), | 
					
						
							| 
									
										
										
										
											2019-12-15 12:16:08 +01:00
										 |  |  |                 ); | 
					
						
							|  |  |  |               }, | 
					
						
							|  |  |  |             ); | 
					
						
							|  |  |  |           } else { | 
					
						
							|  |  |  |             return Container(); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       ), | 
					
						
							| 
									
										
										
										
											2019-12-02 21:05:49 +01:00
										 |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |