lockable items in templates
This commit is contained in:
parent
6b6c96ea43
commit
055fb7241d
|
|
@ -13,6 +13,7 @@ class CheckList extends StatefulWidget {
|
|||
class _CheckList extends State<CheckList> {
|
||||
_CheckList(this.id);
|
||||
final int id;
|
||||
bool _editable = false;
|
||||
data.List? listData;
|
||||
List<data.Check> list = [];
|
||||
|
||||
|
|
@ -36,6 +37,12 @@ class _CheckList extends State<CheckList> {
|
|||
DBHelper.dbHelper.updateItem(item);
|
||||
}
|
||||
|
||||
void _toggleEditable() {
|
||||
setState(() {
|
||||
_editable = !_editable;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_loadList();
|
||||
|
|
@ -49,6 +56,13 @@ class _CheckList extends State<CheckList> {
|
|||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text((listData != null) ? listData!.name : 'Check List: $id'),
|
||||
actions: [
|
||||
(listData != null && listData!.isTemplate! && !_editable)
|
||||
? IconButton(
|
||||
onPressed: () => _toggleEditable(), icon: Icon(Icons.edit))
|
||||
: IconButton(
|
||||
onPressed: () => _toggleEditable(), icon: Icon(Icons.save)),
|
||||
],
|
||||
),
|
||||
body: ListView.builder(
|
||||
itemCount: list.length,
|
||||
|
|
@ -58,14 +72,15 @@ class _CheckList extends State<CheckList> {
|
|||
title: Text(list[index].text),
|
||||
controlAffinity: ListTileControlAffinity.leading,
|
||||
value: list[index].value,
|
||||
onChanged: (listData != null && !listData!.isTemplate!)
|
||||
? ((value) {
|
||||
_updateItem(list[index]);
|
||||
setState(() {
|
||||
list[index].value = value!;
|
||||
});
|
||||
})
|
||||
: null,
|
||||
onChanged:
|
||||
(listData != null && (!listData!.isTemplate! || _editable))
|
||||
? ((value) {
|
||||
_updateItem(list[index]);
|
||||
setState(() {
|
||||
list[index].value = value!;
|
||||
});
|
||||
})
|
||||
: null,
|
||||
),
|
||||
);
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue