mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 18:57:25 +01:00
Add role selector
This commit is contained in:
parent
63c4ccf364
commit
8a9d71694d
1 changed files with 53 additions and 0 deletions
53
lib/selectors/role.dart
Normal file
53
lib/selectors/role.dart
Normal file
|
|
@ -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<List<Role>>(
|
||||
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);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue