mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 10:47:25 +01:00
Add composers and work texts
These replace the work tile widget.
This commit is contained in:
parent
40db00d88d
commit
e834abe1e0
4 changed files with 68 additions and 87 deletions
|
|
@ -4,7 +4,7 @@ import '../backend.dart';
|
|||
import '../database.dart';
|
||||
import '../selectors/performer.dart';
|
||||
import '../selectors/work.dart';
|
||||
import '../widgets/work_tile.dart';
|
||||
import '../widgets/texts.dart';
|
||||
|
||||
class RecordingEditor extends StatefulWidget {
|
||||
final Recording recording;
|
||||
|
|
@ -70,10 +70,10 @@ class _RecordingEditorState extends State<RecordingEditor> {
|
|||
body: ListView(
|
||||
children: <Widget>[
|
||||
work != null
|
||||
? WorkTile(
|
||||
workId: work.id,
|
||||
onTap: selectWork,
|
||||
)
|
||||
? ListTile(
|
||||
title: WorkText(work.id),
|
||||
subtitle: ComposersText(work.id),
|
||||
)
|
||||
: ListTile(
|
||||
title: Text('Work'),
|
||||
subtitle: Text('Select work'),
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import '../database.dart';
|
|||
import '../editors/recording.dart';
|
||||
import '../widgets/texts.dart';
|
||||
import '../widgets/works_by_composer.dart';
|
||||
import '../widgets/work_tile.dart';
|
||||
|
||||
class PersonList extends StatelessWidget {
|
||||
final void Function(int personId) onSelect;
|
||||
|
|
@ -102,12 +101,13 @@ class RecordingList extends StatelessWidget {
|
|||
children: <Widget>[
|
||||
Material(
|
||||
elevation: 2.0,
|
||||
child: WorkTile(
|
||||
child: ListTile(
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
workId: workId,
|
||||
title: WorkText(workId),
|
||||
subtitle: ComposersText(workId),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
|
|
|
|||
|
|
@ -74,33 +74,36 @@ class _PerformancesTextState extends State<PerformancesText> {
|
|||
.performancesByRecording(widget.recordingId)
|
||||
.watch()
|
||||
.listen((performances) async {
|
||||
final List<String> texts = [];
|
||||
final List<String> texts = [];
|
||||
|
||||
for (final performance in performances) {
|
||||
final buffer = StringBuffer();
|
||||
for (final performance in performances) {
|
||||
final buffer = StringBuffer();
|
||||
|
||||
if (performance.person != null) {
|
||||
final person = await backend.db.personById(performance.person).getSingle();
|
||||
buffer.write('${person.firstName} ${person.lastName}');
|
||||
} else if (performance.ensemble != null) {
|
||||
final ensemble = await backend.db.ensembleById(performance.ensemble).getSingle();
|
||||
buffer.write(ensemble.name);
|
||||
} else {
|
||||
buffer.write('Unknown');
|
||||
}
|
||||
if (performance.person != null) {
|
||||
final person =
|
||||
await backend.db.personById(performance.person).getSingle();
|
||||
buffer.write('${person.firstName} ${person.lastName}');
|
||||
} else if (performance.ensemble != null) {
|
||||
final ensemble =
|
||||
await backend.db.ensembleById(performance.ensemble).getSingle();
|
||||
buffer.write(ensemble.name);
|
||||
} else {
|
||||
buffer.write('Unknown');
|
||||
}
|
||||
|
||||
if (performance.role != null) {
|
||||
final role = await backend.db.instrumentById(performance.role).getSingle();
|
||||
buffer.write(' (${role.name})');
|
||||
}
|
||||
if (performance.role != null) {
|
||||
final role =
|
||||
await backend.db.instrumentById(performance.role).getSingle();
|
||||
buffer.write(' (${role.name})');
|
||||
}
|
||||
|
||||
texts.add(buffer.toString());
|
||||
}
|
||||
texts.add(buffer.toString());
|
||||
}
|
||||
|
||||
setState(() {
|
||||
text = texts.join(', ');
|
||||
});
|
||||
});
|
||||
setState(() {
|
||||
text = texts.join(', ');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
@ -113,4 +116,38 @@ class _PerformancesTextState extends State<PerformancesText> {
|
|||
super.dispose();
|
||||
performancesSubscription?.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class WorkText extends StatelessWidget {
|
||||
final int workId;
|
||||
|
||||
WorkText(this.workId);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final backend = Backend.of(context);
|
||||
|
||||
return StreamBuilder<Work>(
|
||||
stream: backend.db.workById(workId).watchSingle(),
|
||||
builder: (context, snapshot) => Text(snapshot.data?.title ?? '...'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ComposersText extends StatelessWidget {
|
||||
final int workId;
|
||||
|
||||
ComposersText(this.workId);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final backend = Backend.of(context);
|
||||
|
||||
return StreamBuilder<List<Person>>(
|
||||
stream: backend.db.composersByWork(workId).watch(),
|
||||
builder: (context, snapshot) => Text(snapshot.hasData
|
||||
? snapshot.data.map((p) => '${p.firstName} ${p.lastName}').join(', ')
|
||||
: '...'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,56 +0,0 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../backend.dart';
|
||||
import '../database.dart';
|
||||
|
||||
class WorkTile extends StatelessWidget {
|
||||
final Widget leading;
|
||||
final int workId;
|
||||
final void Function() onTap;
|
||||
|
||||
WorkTile({
|
||||
this.leading,
|
||||
this.workId,
|
||||
this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final backend = Backend.of(context);
|
||||
|
||||
return StreamBuilder<Work>(
|
||||
stream: backend.db.workById(workId).watchSingle(),
|
||||
builder: (context, snapshot) {
|
||||
final titleText = snapshot.data?.title ?? '...';
|
||||
|
||||
return StreamBuilder<List<Person>>(
|
||||
stream: backend.db.composersByWork(workId).watch(),
|
||||
builder: (context, snapshot) {
|
||||
final subtitleText = snapshot.hasData
|
||||
? snapshot.data
|
||||
.map((p) => '${p.firstName} ${p.lastName}')
|
||||
.join(', ')
|
||||
: '...';
|
||||
return ListTile(
|
||||
leading: leading,
|
||||
title: DefaultTextStyle(
|
||||
style: Theme.of(context).textTheme.bodyText2,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
subtitleText,
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
Text(titleText),
|
||||
],
|
||||
),
|
||||
),
|
||||
onTap: onTap ?? null,
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue