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 '../database.dart';
|
||||||
import '../selectors/performer.dart';
|
import '../selectors/performer.dart';
|
||||||
import '../selectors/work.dart';
|
import '../selectors/work.dart';
|
||||||
import '../widgets/work_tile.dart';
|
import '../widgets/texts.dart';
|
||||||
|
|
||||||
class RecordingEditor extends StatefulWidget {
|
class RecordingEditor extends StatefulWidget {
|
||||||
final Recording recording;
|
final Recording recording;
|
||||||
|
|
@ -70,10 +70,10 @@ class _RecordingEditorState extends State<RecordingEditor> {
|
||||||
body: ListView(
|
body: ListView(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
work != null
|
work != null
|
||||||
? WorkTile(
|
? ListTile(
|
||||||
workId: work.id,
|
title: WorkText(work.id),
|
||||||
onTap: selectWork,
|
subtitle: ComposersText(work.id),
|
||||||
)
|
)
|
||||||
: ListTile(
|
: ListTile(
|
||||||
title: Text('Work'),
|
title: Text('Work'),
|
||||||
subtitle: Text('Select work'),
|
subtitle: Text('Select work'),
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ import '../database.dart';
|
||||||
import '../editors/recording.dart';
|
import '../editors/recording.dart';
|
||||||
import '../widgets/texts.dart';
|
import '../widgets/texts.dart';
|
||||||
import '../widgets/works_by_composer.dart';
|
import '../widgets/works_by_composer.dart';
|
||||||
import '../widgets/work_tile.dart';
|
|
||||||
|
|
||||||
class PersonList extends StatelessWidget {
|
class PersonList extends StatelessWidget {
|
||||||
final void Function(int personId) onSelect;
|
final void Function(int personId) onSelect;
|
||||||
|
|
@ -102,12 +101,13 @@ class RecordingList extends StatelessWidget {
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Material(
|
Material(
|
||||||
elevation: 2.0,
|
elevation: 2.0,
|
||||||
child: WorkTile(
|
child: ListTile(
|
||||||
leading: IconButton(
|
leading: IconButton(
|
||||||
icon: const Icon(Icons.arrow_back),
|
icon: const Icon(Icons.arrow_back),
|
||||||
onPressed: () => Navigator.pop(context),
|
onPressed: () => Navigator.pop(context),
|
||||||
),
|
),
|
||||||
workId: workId,
|
title: WorkText(workId),
|
||||||
|
subtitle: ComposersText(workId),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
|
|
|
||||||
|
|
@ -74,33 +74,36 @@ class _PerformancesTextState extends State<PerformancesText> {
|
||||||
.performancesByRecording(widget.recordingId)
|
.performancesByRecording(widget.recordingId)
|
||||||
.watch()
|
.watch()
|
||||||
.listen((performances) async {
|
.listen((performances) async {
|
||||||
final List<String> texts = [];
|
final List<String> texts = [];
|
||||||
|
|
||||||
for (final performance in performances) {
|
for (final performance in performances) {
|
||||||
final buffer = StringBuffer();
|
final buffer = StringBuffer();
|
||||||
|
|
||||||
if (performance.person != null) {
|
if (performance.person != null) {
|
||||||
final person = await backend.db.personById(performance.person).getSingle();
|
final person =
|
||||||
buffer.write('${person.firstName} ${person.lastName}');
|
await backend.db.personById(performance.person).getSingle();
|
||||||
} else if (performance.ensemble != null) {
|
buffer.write('${person.firstName} ${person.lastName}');
|
||||||
final ensemble = await backend.db.ensembleById(performance.ensemble).getSingle();
|
} else if (performance.ensemble != null) {
|
||||||
buffer.write(ensemble.name);
|
final ensemble =
|
||||||
} else {
|
await backend.db.ensembleById(performance.ensemble).getSingle();
|
||||||
buffer.write('Unknown');
|
buffer.write(ensemble.name);
|
||||||
}
|
} else {
|
||||||
|
buffer.write('Unknown');
|
||||||
|
}
|
||||||
|
|
||||||
if (performance.role != null) {
|
if (performance.role != null) {
|
||||||
final role = await backend.db.instrumentById(performance.role).getSingle();
|
final role =
|
||||||
buffer.write(' (${role.name})');
|
await backend.db.instrumentById(performance.role).getSingle();
|
||||||
}
|
buffer.write(' (${role.name})');
|
||||||
|
}
|
||||||
|
|
||||||
texts.add(buffer.toString());
|
texts.add(buffer.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
text = texts.join(', ');
|
text = texts.join(', ');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -113,4 +116,38 @@ class _PerformancesTextState extends State<PerformancesText> {
|
||||||
super.dispose();
|
super.dispose();
|
||||||
performancesSubscription?.cancel();
|
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