From 8a9d71694dce27e729275312aff3b7fe9c14d350 Mon Sep 17 00:00:00 2001 From: Elias Projahn Date: Sun, 22 Mar 2020 15:11:23 +0100 Subject: [PATCH] Add role selector --- lib/selectors/role.dart | 53 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 lib/selectors/role.dart diff --git a/lib/selectors/role.dart b/lib/selectors/role.dart new file mode 100644 index 0000000..1ecd4aa --- /dev/null +++ b/lib/selectors/role.dart @@ -0,0 +1,53 @@ +import 'package:flutter/material.dart'; + +import '../backend.dart'; +import '../database.dart'; +import '../editors/role.dart'; + +class RolesSelector extends StatelessWidget { + @override + Widget build(BuildContext context) { + final backend = Backend.of(context); + + return Scaffold( + appBar: AppBar( + title: Text('Select role'), + ), + body: StreamBuilder>( + stream: backend.db.allRoles().watch(), + builder: (context, snapshot) { + if (snapshot.hasData) { + return ListView.builder( + itemCount: snapshot.data.length, + itemBuilder: (context, index) { + final role = snapshot.data[index]; + + return ListTile( + title: Text(role.name), + onTap: () => Navigator.pop(context, role), + ); + }, + ); + } else { + return Container(); + } + }, + ), + floatingActionButton: FloatingActionButton( + child: const Icon(Icons.add), + onPressed: () async { + final Role role = await Navigator.push( + context, + MaterialPageRoute( + builder: (context) => RoleEditor(), + fullscreenDialog: true, + )); + + if (role != null) { + Navigator.pop(context, role); + } + }, + ), + ); + } +}