2019-12-04 20:48:55 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2020-04-24 22:41:52 +02:00
|
|
|
import 'package:musicus_database/musicus_database.dart';
|
2019-12-04 20:48:55 +01:00
|
|
|
|
|
|
|
|
import '../backend.dart';
|
2019-12-04 20:52:52 +01:00
|
|
|
import '../editors/person.dart';
|
2019-12-04 20:48:55 +01:00
|
|
|
|
|
|
|
|
class PersonsSelector extends StatelessWidget {
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final backend = Backend.of(context);
|
|
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
title: Text('Select person'),
|
|
|
|
|
),
|
|
|
|
|
body: StreamBuilder(
|
2019-12-04 20:52:52 +01:00
|
|
|
stream: backend.db.allPersons().watch(),
|
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
|
return ListView.builder(
|
|
|
|
|
itemCount: snapshot.data.length,
|
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
|
final person = snapshot.data[index];
|
2019-12-04 20:48:55 +01:00
|
|
|
|
2019-12-04 20:52:52 +01:00
|
|
|
return ListTile(
|
|
|
|
|
title: Text('${person.lastName}, ${person.firstName}'),
|
|
|
|
|
onTap: () => Navigator.pop(context, person),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
return Container();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
floatingActionButton: FloatingActionButton(
|
|
|
|
|
child: const Icon(Icons.add),
|
|
|
|
|
onPressed: () async {
|
|
|
|
|
final Person person = await Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
builder: (context) => PersonEditor(),
|
|
|
|
|
fullscreenDialog: true,
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
if (person != null) {
|
|
|
|
|
Navigator.pop(context, person);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
),
|
2019-12-04 20:48:55 +01:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|