musicus_mobile/mobile/lib/selectors/recording.dart

91 lines
2.1 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2020-04-24 22:41:52 +02:00
import 'package:musicus_database/musicus_database.dart';
import '../editors/recording.dart';
2020-04-26 15:35:45 +02:00
import '../widgets/lists.dart';
2020-04-26 15:35:45 +02:00
class RecordingSelectorResult {
final WorkInfo workInfo;
final RecordingInfo recordingInfo;
2020-04-26 15:35:45 +02:00
RecordingSelectorResult({
this.workInfo,
this.recordingInfo,
});
}
2020-04-26 15:35:45 +02:00
/// A screen to select a recording.
///
/// If the user has selected a recording, a [RecordingSelectorResult] containing
/// the selected recording and the recorded work will be returned using the
/// navigator.
class RecordingSelector extends StatefulWidget {
@override
2020-04-26 15:35:45 +02:00
_RecordingSelectorState createState() => _RecordingSelectorState();
}
2020-04-26 15:35:45 +02:00
class _RecordingSelectorState extends State<RecordingSelector> {
Person person;
WorkInfo workInfo;
@override
Widget build(BuildContext context) {
2020-04-26 15:35:45 +02:00
Widget body;
if (person == null) {
body = PersonsList(
onSelected: (newPerson) {
setState(() {
person = newPerson;
});
},
);
} else if (workInfo == null) {
body = WorksList(
personId: person.id,
onSelected: (newWorkInfo) {
setState(() {
workInfo = newWorkInfo;
});
},
);
} else {
body = RecordingsList(
workId: workInfo.work.id,
onSelected: (recordingInfo) {
Navigator.pop(
context,
RecordingSelectorResult(
workInfo: workInfo,
recordingInfo: recordingInfo,
),
2020-04-26 15:35:45 +02:00
);
},
);
}
2020-04-26 15:35:45 +02:00
return Scaffold(
appBar: AppBar(
title: Text('Select recording'),
),
body: body,
floatingActionButton: FloatingActionButton(
child: const Icon(Icons.add),
onPressed: () async {
final RecordingSelectorResult result = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => RecordingEditor(),
fullscreenDialog: true,
),
);
2020-04-26 15:35:45 +02:00
if (result != null) {
Navigator.pop(context, result);
}
},
),
);
}
}