2020-04-05 19:31:46 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2020-04-24 22:41:52 +02:00
|
|
|
import 'package:musicus_database/musicus_database.dart';
|
2020-04-05 19:31:46 +02:00
|
|
|
|
|
|
|
|
import '../backend.dart';
|
|
|
|
|
import '../editors/recording.dart';
|
2020-04-06 11:15:05 +02:00
|
|
|
import '../widgets/texts.dart';
|
2020-04-05 19:31:46 +02:00
|
|
|
import '../widgets/works_by_composer.dart';
|
|
|
|
|
|
2020-04-05 20:46:00 +02:00
|
|
|
class PersonList extends StatelessWidget {
|
|
|
|
|
final void Function(int personId) onSelect;
|
|
|
|
|
|
|
|
|
|
PersonList({
|
|
|
|
|
this.onSelect,
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-05 19:31:46 +02:00
|
|
|
@override
|
2020-04-05 20:46:00 +02:00
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final backend = Backend.of(context);
|
|
|
|
|
|
|
|
|
|
return Column(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Material(
|
|
|
|
|
elevation: 2.0,
|
|
|
|
|
child: ListTile(
|
|
|
|
|
title: Text('Composers'),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: 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}'),
|
|
|
|
|
onTap: () => onSelect(person.id),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
return Container();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
2020-04-05 19:31:46 +02:00
|
|
|
}
|
|
|
|
|
|
2020-04-05 20:46:00 +02:00
|
|
|
class WorkList extends StatelessWidget {
|
|
|
|
|
final int composerId;
|
|
|
|
|
final void Function(int workId) onSelect;
|
|
|
|
|
|
|
|
|
|
WorkList({
|
|
|
|
|
this.composerId,
|
|
|
|
|
this.onSelect,
|
|
|
|
|
});
|
2020-04-05 19:31:46 +02:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2020-04-05 20:46:00 +02:00
|
|
|
return Column(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Material(
|
|
|
|
|
elevation: 2.0,
|
|
|
|
|
child: ListTile(
|
|
|
|
|
leading: IconButton(
|
|
|
|
|
icon: const Icon(Icons.arrow_back),
|
|
|
|
|
onPressed: () => Navigator.pop(context),
|
|
|
|
|
),
|
|
|
|
|
title: PersonText(composerId),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: WorksByComposer(
|
|
|
|
|
personId: composerId,
|
|
|
|
|
onTap: (selectedWork) => onSelect(selectedWork.id),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-05 19:31:46 +02:00
|
|
|
|
2020-04-05 20:46:00 +02:00
|
|
|
class RecordingList extends StatelessWidget {
|
|
|
|
|
final int workId;
|
|
|
|
|
final void Function(Recording recording) onSelect;
|
2020-04-05 19:31:46 +02:00
|
|
|
|
2020-04-05 20:46:00 +02:00
|
|
|
RecordingList({
|
|
|
|
|
this.workId,
|
|
|
|
|
this.onSelect,
|
|
|
|
|
});
|
2020-04-05 19:31:46 +02:00
|
|
|
|
2020-04-05 20:46:00 +02:00
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final backend = Backend.of(context);
|
|
|
|
|
return Column(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Material(
|
|
|
|
|
elevation: 2.0,
|
2020-04-06 11:29:55 +02:00
|
|
|
child: ListTile(
|
2020-04-05 20:46:00 +02:00
|
|
|
leading: IconButton(
|
|
|
|
|
icon: const Icon(Icons.arrow_back),
|
|
|
|
|
onPressed: () => Navigator.pop(context),
|
|
|
|
|
),
|
2020-04-06 11:29:55 +02:00
|
|
|
title: WorkText(workId),
|
|
|
|
|
subtitle: ComposersText(workId),
|
2020-04-05 20:46:00 +02:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: StreamBuilder<List<Recording>>(
|
|
|
|
|
stream: backend.db.recordingsByWork(workId).watch(),
|
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
|
return ListView.builder(
|
|
|
|
|
itemCount: snapshot.data.length,
|
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
|
final recording = snapshot.data[index];
|
|
|
|
|
return ListTile(
|
2020-04-06 11:15:05 +02:00
|
|
|
title: PerformancesText(recording.id),
|
2020-04-05 20:46:00 +02:00
|
|
|
onTap: () => onSelect(recording),
|
|
|
|
|
);
|
2020-04-05 19:31:46 +02:00
|
|
|
},
|
|
|
|
|
);
|
2020-04-05 20:46:00 +02:00
|
|
|
} else {
|
|
|
|
|
return Container();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class RecordingsSelector extends StatefulWidget {
|
|
|
|
|
@override
|
|
|
|
|
_RecordingsSelectorState createState() => _RecordingsSelectorState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _RecordingsSelectorState extends State<RecordingsSelector> {
|
|
|
|
|
final nestedNavigator = GlobalKey<NavigatorState>();
|
2020-04-06 11:15:05 +02:00
|
|
|
|
2020-04-05 20:46:00 +02:00
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
// This exists to circumvent the nested navigator when selecting a
|
|
|
|
|
// recording.
|
|
|
|
|
void popUpperNavigator(Recording recording) {
|
|
|
|
|
Navigator.pop(context, recording);
|
2020-04-05 19:31:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return WillPopScope(
|
|
|
|
|
child: Scaffold(
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
leading: IconButton(
|
|
|
|
|
icon: const Icon(Icons.close),
|
|
|
|
|
onPressed: () => Navigator.pop(context),
|
|
|
|
|
),
|
|
|
|
|
title: Text('Select recording'),
|
|
|
|
|
),
|
2020-04-05 20:46:00 +02:00
|
|
|
body: Navigator(
|
|
|
|
|
key: nestedNavigator,
|
|
|
|
|
onGenerateRoute: (settings) => settings.name == '/'
|
|
|
|
|
? MaterialPageRoute(
|
|
|
|
|
builder: (context) => PersonList(
|
|
|
|
|
onSelect: (personId) => nestedNavigator.currentState.push(
|
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
builder: (context) => WorkList(
|
|
|
|
|
composerId: personId,
|
|
|
|
|
onSelect: (workId) =>
|
|
|
|
|
nestedNavigator.currentState.push(
|
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
builder: (context) => RecordingList(
|
|
|
|
|
workId: workId,
|
2020-04-06 11:15:05 +02:00
|
|
|
onSelect: (recording) =>
|
|
|
|
|
popUpperNavigator(recording),
|
2020-04-05 20:46:00 +02:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: null,
|
|
|
|
|
initialRoute: '/',
|
2020-04-05 19:31:46 +02:00
|
|
|
),
|
|
|
|
|
floatingActionButton: FloatingActionButton(
|
|
|
|
|
child: const Icon(Icons.add),
|
|
|
|
|
onPressed: () async {
|
|
|
|
|
final recording = await Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
builder: (context) => RecordingEditor(),
|
|
|
|
|
fullscreenDialog: true,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (recording != null) {
|
|
|
|
|
Navigator.pop(context, recording);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
2020-04-05 20:46:00 +02:00
|
|
|
onWillPop: () async => !(await nestedNavigator.currentState.maybePop()),
|
2020-04-05 19:31:46 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|