mobile: Integrate with server

This commit is contained in:
Elias Projahn 2020-04-26 15:35:45 +02:00
parent 60a474ea56
commit c93ebf17a0
20 changed files with 751 additions and 740 deletions

View file

@ -1,47 +1,35 @@
import 'package:flutter/material.dart';
import 'package:musicus_database/musicus_database.dart';
import '../backend.dart';
import '../editors/person.dart';
import '../widgets/lists.dart';
/// A screen to select a person.
///
/// If the user has selected a person, it will be returned as a [Person] object
/// using the navigator.
class PersonsSelector extends StatelessWidget {
@override
Widget build(BuildContext context) {
final backend = Backend.of(context);
return Scaffold(
appBar: AppBar(
title: Text('Select person'),
),
body: StreamBuilder(
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];
return ListTile(
title: Text('${person.lastName}, ${person.firstName}'),
onTap: () => Navigator.pop(context, person),
);
},
);
} else {
return Container();
}
body: PersonsList(
onSelected: (person) {
Navigator.pop(context, person);
},
),
floatingActionButton: FloatingActionButton(
child: const Icon(Icons.add),
onPressed: () async {
final Person person = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PersonEditor(),
fullscreenDialog: true,
));
context,
MaterialPageRoute(
builder: (context) => PersonEditor(),
fullscreenDialog: true,
),
);
if (person != null) {
Navigator.pop(context, person);