mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 10:47:25 +01:00
Add role editor
This commit is contained in:
parent
4092a91f56
commit
36c79c7b82
1 changed files with 66 additions and 0 deletions
66
lib/editors/role.dart
Normal file
66
lib/editors/role.dart
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../backend.dart';
|
||||||
|
import '../database.dart';
|
||||||
|
|
||||||
|
class RoleEditor extends StatefulWidget {
|
||||||
|
final Role role;
|
||||||
|
|
||||||
|
RoleEditor({
|
||||||
|
this.role,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
_RoleEditorState createState() => _RoleEditorState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RoleEditorState extends State<RoleEditor> {
|
||||||
|
final nameController = TextEditingController();
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
if (widget.role != null) {
|
||||||
|
nameController.text = widget.role.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final backend = Backend.of(context);
|
||||||
|
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: Text('Role'),
|
||||||
|
actions: <Widget>[
|
||||||
|
FlatButton(
|
||||||
|
child: Text('DONE'),
|
||||||
|
onPressed: () async {
|
||||||
|
final role = Role(
|
||||||
|
id: widget.role?.id ?? generateId(),
|
||||||
|
name: nameController.text,
|
||||||
|
);
|
||||||
|
|
||||||
|
await backend.db.updateRole(role);
|
||||||
|
Navigator.pop(context, role);
|
||||||
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
body: ListView(
|
||||||
|
children: <Widget>[
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(16.0),
|
||||||
|
child: TextField(
|
||||||
|
controller: nameController,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
labelText: 'Name',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue