mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 18:57:25 +01:00
Allow selecting and adding ensembles
This commit is contained in:
parent
99e4711cfc
commit
8f0463a1a1
1 changed files with 119 additions and 40 deletions
|
|
@ -2,19 +2,33 @@ import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../backend.dart';
|
import '../backend.dart';
|
||||||
import '../database.dart';
|
import '../database.dart';
|
||||||
|
import '../editors/ensemble.dart';
|
||||||
import '../editors/person.dart';
|
import '../editors/person.dart';
|
||||||
|
|
||||||
import 'instruments.dart';
|
import 'instruments.dart';
|
||||||
|
|
||||||
// TODO: Allow selecting and adding ensembles.
|
|
||||||
class PerformerSelector extends StatefulWidget {
|
class PerformerSelector extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
_PerformerSelectorState createState() => _PerformerSelectorState();
|
_PerformerSelectorState createState() => _PerformerSelectorState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _Selection {
|
||||||
|
final bool isPerson;
|
||||||
|
final Person person;
|
||||||
|
final Ensemble ensemble;
|
||||||
|
|
||||||
|
_Selection.person(this.person)
|
||||||
|
: isPerson = true,
|
||||||
|
ensemble = null;
|
||||||
|
|
||||||
|
_Selection.ensemble(this.ensemble)
|
||||||
|
: isPerson = false,
|
||||||
|
person = null;
|
||||||
|
}
|
||||||
|
|
||||||
class _PerformerSelectorState extends State<PerformerSelector> {
|
class _PerformerSelectorState extends State<PerformerSelector> {
|
||||||
Instrument role;
|
Instrument role;
|
||||||
Person person;
|
_Selection selection;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
@ -29,7 +43,8 @@ class _PerformerSelectorState extends State<PerformerSelector> {
|
||||||
onPressed: () => Navigator.pop(
|
onPressed: () => Navigator.pop(
|
||||||
context,
|
context,
|
||||||
PerformanceModel(
|
PerformanceModel(
|
||||||
person: person,
|
person: selection?.person,
|
||||||
|
ensemble: selection?.ensemble,
|
||||||
role: role,
|
role: role,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
@ -69,32 +84,60 @@ class _PerformerSelectorState extends State<PerformerSelector> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: StreamBuilder(
|
child: ListView(
|
||||||
stream: backend.db.allPersons().watch(),
|
children: <Widget>[
|
||||||
builder: (context, snapshot) {
|
StreamBuilder<List<Person>>(
|
||||||
if (snapshot.hasData) {
|
stream: backend.db.allPersons().watch(),
|
||||||
return ListView.builder(
|
builder: (context, snapshot) {
|
||||||
itemCount: snapshot.data.length,
|
if (snapshot.hasData && snapshot.data.isNotEmpty) {
|
||||||
itemBuilder: (context, index) {
|
return ExpansionTile(
|
||||||
final person = snapshot.data[index];
|
initiallyExpanded: true,
|
||||||
|
title: Text('Persons'),
|
||||||
return RadioListTile<Person>(
|
children: snapshot.data
|
||||||
controlAffinity: ListTileControlAffinity.trailing,
|
.map((person) => RadioListTile<Person>(
|
||||||
title:
|
title: Text(
|
||||||
Text('${person.lastName}, ${person.firstName}'),
|
'${person.lastName}, ${person.firstName}'),
|
||||||
value: person,
|
value: person,
|
||||||
groupValue: this.person,
|
groupValue: selection?.person,
|
||||||
onChanged: (newPerson) {
|
onChanged: (person) {
|
||||||
setState(() {
|
setState(() {
|
||||||
this.person = newPerson;
|
selection = _Selection.person(person);
|
||||||
});
|
});
|
||||||
});
|
},
|
||||||
},
|
))
|
||||||
);
|
.toList(),
|
||||||
} else {
|
);
|
||||||
return Container();
|
} else {
|
||||||
}
|
return Container();
|
||||||
},
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
StreamBuilder<List<Ensemble>>(
|
||||||
|
stream: backend.db.allEnsembles().watch(),
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
if (snapshot.hasData && snapshot.data.isNotEmpty) {
|
||||||
|
return ExpansionTile(
|
||||||
|
initiallyExpanded: true,
|
||||||
|
title: Text('Ensembles'),
|
||||||
|
children: snapshot.data
|
||||||
|
.map((ensemble) => RadioListTile<Ensemble>(
|
||||||
|
title: Text(ensemble.name),
|
||||||
|
value: ensemble,
|
||||||
|
groupValue: selection?.ensemble,
|
||||||
|
onChanged: (ensemble) {
|
||||||
|
setState(() {
|
||||||
|
selection = _Selection.ensemble(ensemble);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
))
|
||||||
|
.toList(),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return Container();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
@ -102,18 +145,54 @@ class _PerformerSelectorState extends State<PerformerSelector> {
|
||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: FloatingActionButton(
|
||||||
child: const Icon(Icons.add),
|
child: const Icon(Icons.add),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
final Person person = await Navigator.push(
|
showModalBottomSheet(
|
||||||
context,
|
context: context,
|
||||||
MaterialPageRoute(
|
builder: (context) => Column(
|
||||||
builder: (context) => PersonEditor(),
|
mainAxisSize: MainAxisSize.min,
|
||||||
fullscreenDialog: true,
|
children: <Widget>[
|
||||||
));
|
ListTile(
|
||||||
|
leading: const Icon(Icons.add),
|
||||||
|
title: Text('Add person'),
|
||||||
|
onTap: () async {
|
||||||
|
final Person person = await Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => PersonEditor(),
|
||||||
|
fullscreenDialog: true,
|
||||||
|
));
|
||||||
|
|
||||||
if (person != null) {
|
if (person != null) {
|
||||||
setState(() {
|
setState(() {
|
||||||
this.person = person;
|
selection = _Selection.person(person);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.add),
|
||||||
|
title: Text('Add ensemble'),
|
||||||
|
onTap: () async {
|
||||||
|
final Ensemble ensemble = await Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => EnsembleEditor(),
|
||||||
|
fullscreenDialog: true,
|
||||||
|
));
|
||||||
|
|
||||||
|
if (ensemble != null) {
|
||||||
|
setState(() {
|
||||||
|
selection = _Selection.ensemble(ensemble);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue