mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 10:47:25 +01:00
Bundle text widgets and refactor performances row
This commit is contained in:
parent
3a9a3100fc
commit
40db00d88d
5 changed files with 121 additions and 116 deletions
|
|
@ -1,12 +1,11 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:musicus/widgets/person_text.dart';
|
||||
|
||||
import '../backend.dart';
|
||||
import '../database.dart';
|
||||
import '../editors/recording.dart';
|
||||
import '../widgets/texts.dart';
|
||||
import '../widgets/works_by_composer.dart';
|
||||
import '../widgets/work_tile.dart';
|
||||
import '../widgets/performance_row.dart';
|
||||
|
||||
class PersonList extends StatelessWidget {
|
||||
final void Function(int personId) onSelect;
|
||||
|
|
@ -121,24 +120,7 @@ class RecordingList extends StatelessWidget {
|
|||
itemBuilder: (context, index) {
|
||||
final recording = snapshot.data[index];
|
||||
return ListTile(
|
||||
title: StreamBuilder<List<Performance>>(
|
||||
stream: backend.db
|
||||
.performancesByRecording(recording.id)
|
||||
.watch(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
for (final performance in snapshot.data)
|
||||
PerformanceRow(performance),
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return Container();
|
||||
}
|
||||
},
|
||||
),
|
||||
title: PerformancesText(recording.id),
|
||||
onTap: () => onSelect(recording),
|
||||
);
|
||||
},
|
||||
|
|
@ -193,7 +175,8 @@ class _RecordingsSelectorState extends State<RecordingsSelector> {
|
|||
MaterialPageRoute(
|
||||
builder: (context) => RecordingList(
|
||||
workId: workId,
|
||||
onSelect: (recording) => popUpperNavigator(recording),
|
||||
onSelect: (recording) =>
|
||||
popUpperNavigator(recording),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -1,26 +0,0 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../backend.dart';
|
||||
import '../database.dart';
|
||||
|
||||
class EnsembleText extends StatelessWidget {
|
||||
final int ensembleId;
|
||||
|
||||
EnsembleText(this.ensembleId);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final backend = Backend.of(context);
|
||||
|
||||
return StreamBuilder<Ensemble>(
|
||||
stream: backend.db.ensembleById(ensembleId).watchSingle(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return Text(snapshot.data.name);
|
||||
} else {
|
||||
return Container();
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../backend.dart';
|
||||
import '../database.dart';
|
||||
|
||||
import 'person_text.dart';
|
||||
import 'ensemble_text.dart';
|
||||
|
||||
class PerformanceRow extends StatelessWidget {
|
||||
final Performance performance;
|
||||
|
||||
PerformanceRow(this.performance);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final backend = Backend.of(context);
|
||||
|
||||
return Row(
|
||||
children: <Widget>[
|
||||
if (performance.person != null)
|
||||
PersonText(performance.person)
|
||||
else if (performance.ensemble != null)
|
||||
EnsembleText(performance.ensemble),
|
||||
if (performance.role != null) ...[
|
||||
SizedBox(
|
||||
width: 4.0,
|
||||
),
|
||||
StreamBuilder<Instrument>(
|
||||
stream: backend.db.instrumentById(performance.role).watchSingle(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return Text('(${snapshot.data.name})');
|
||||
} else {
|
||||
return Container();
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../backend.dart';
|
||||
import '../database.dart';
|
||||
|
||||
class PersonText extends StatelessWidget {
|
||||
final int personId;
|
||||
|
||||
PersonText(this.personId);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final backend = Backend.of(context);
|
||||
|
||||
return StreamBuilder<Person>(
|
||||
stream: backend.db.personById(personId).watchSingle(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return Text('${snapshot.data.firstName} ${snapshot.data.lastName}');
|
||||
} else {
|
||||
return Container();
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
116
lib/widgets/texts.dart
Normal file
116
lib/widgets/texts.dart
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../backend.dart';
|
||||
import '../database.dart';
|
||||
|
||||
class EnsembleText extends StatelessWidget {
|
||||
final int ensembleId;
|
||||
|
||||
EnsembleText(this.ensembleId);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final backend = Backend.of(context);
|
||||
|
||||
return StreamBuilder<Ensemble>(
|
||||
stream: backend.db.ensembleById(ensembleId).watchSingle(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return Text(snapshot.data.name);
|
||||
} else {
|
||||
return Container();
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class PersonText extends StatelessWidget {
|
||||
final int personId;
|
||||
|
||||
PersonText(this.personId);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final backend = Backend.of(context);
|
||||
|
||||
return StreamBuilder<Person>(
|
||||
stream: backend.db.personById(personId).watchSingle(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return Text('${snapshot.data.firstName} ${snapshot.data.lastName}');
|
||||
} else {
|
||||
return Container();
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class PerformancesText extends StatefulWidget {
|
||||
final int recordingId;
|
||||
|
||||
PerformancesText(this.recordingId);
|
||||
|
||||
@override
|
||||
_PerformancesTextState createState() => _PerformancesTextState();
|
||||
}
|
||||
|
||||
class _PerformancesTextState extends State<PerformancesText> {
|
||||
BackendState backend;
|
||||
StreamSubscription<List<Performance>> performancesSubscription;
|
||||
String text = '...';
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
|
||||
performancesSubscription?.cancel();
|
||||
backend = Backend.of(context);
|
||||
|
||||
performancesSubscription = backend.db
|
||||
.performancesByRecording(widget.recordingId)
|
||||
.watch()
|
||||
.listen((performances) async {
|
||||
final List<String> texts = [];
|
||||
|
||||
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.role != null) {
|
||||
final role = await backend.db.instrumentById(performance.role).getSingle();
|
||||
buffer.write(' (${role.name})');
|
||||
}
|
||||
|
||||
texts.add(buffer.toString());
|
||||
}
|
||||
|
||||
setState(() {
|
||||
text = texts.join(', ');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Text(text);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
performancesSubscription?.cancel();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue