2020-04-05 20:11:11 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
|
|
import '../backend.dart';
|
|
|
|
|
import '../database.dart';
|
|
|
|
|
|
|
|
|
|
class WorkTile extends StatelessWidget {
|
2020-04-05 20:15:20 +02:00
|
|
|
final Widget leading;
|
2020-04-05 20:11:11 +02:00
|
|
|
final int workId;
|
|
|
|
|
final void Function() onTap;
|
|
|
|
|
|
|
|
|
|
WorkTile({
|
2020-04-05 20:15:20 +02:00
|
|
|
this.leading,
|
2020-04-05 20:11:11 +02:00
|
|
|
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) {
|
2020-04-05 20:15:20 +02:00
|
|
|
final subtitleText = snapshot.hasData
|
|
|
|
|
? snapshot.data
|
2020-04-05 20:11:11 +02:00
|
|
|
.map((p) => '${p.firstName} ${p.lastName}')
|
2020-04-05 20:15:20 +02:00
|
|
|
.join(', ')
|
|
|
|
|
: '...';
|
|
|
|
|
return ListTile(
|
|
|
|
|
leading: leading,
|
|
|
|
|
title: Text(titleText),
|
|
|
|
|
subtitle: Text(subtitleText),
|
|
|
|
|
onTap: onTap ?? null,
|
|
|
|
|
);
|
2020-04-05 20:11:11 +02:00
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|