From cc45018c8324ab50d4a313aab722ae10e1f3b513 Mon Sep 17 00:00:00 2001 From: Elias Projahn Date: Wed, 4 Dec 2019 20:52:52 +0100 Subject: [PATCH] Add access to person editor to person selector The person editor can be reached via the FAB. If a new person is created, it will be selected. --- lib/selectors/person.dart | 52 ++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/lib/selectors/person.dart b/lib/selectors/person.dart index 937e2ac..553c9d0 100644 --- a/lib/selectors/person.dart +++ b/lib/selectors/person.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; import '../backend.dart'; +import '../database.dart'; +import '../editors/person.dart'; class PersonsSelector extends StatelessWidget { @override @@ -12,24 +14,40 @@ class PersonsSelector extends StatelessWidget { 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]; + 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(); - } - }), + 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); + } + }, + ), ); } }