musicus_mobile/mobile/lib/screens/home.dart

81 lines
2.2 KiB
Dart
Raw Normal View History

2019-12-02 21:05:49 +01:00
import 'package:flutter/material.dart';
2020-04-24 22:41:52 +02:00
import 'package:musicus_database/musicus_database.dart';
2019-12-02 21:05:49 +01:00
import '../backend.dart';
import '../editors/tracks.dart';
2020-03-21 17:46:23 +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: 1,
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 == 1) {
2019-12-15 12:11:40 +01:00
Navigator.push(
context,
MaterialPageRoute(
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-02 21:05:49 +01:00
],
),
body: FutureBuilder<List<Person>>(
future: backend.db.getPersons(),
2019-12-15 12:16:08 +01:00
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}'),
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
);
}
}