From 055fb7241dc1432e1fab45427eea0c6273f3e778 Mon Sep 17 00:00:00 2001 From: andrei Date: Wed, 3 Nov 2021 17:42:42 -0400 Subject: [PATCH] lockable items in templates --- lib/check_list.dart | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/lib/check_list.dart b/lib/check_list.dart index 4b62808..7b3969e 100644 --- a/lib/check_list.dart +++ b/lib/check_list.dart @@ -13,6 +13,7 @@ class CheckList extends StatefulWidget { class _CheckList extends State { _CheckList(this.id); final int id; + bool _editable = false; data.List? listData; List list = []; @@ -36,6 +37,12 @@ class _CheckList extends State { DBHelper.dbHelper.updateItem(item); } + void _toggleEditable() { + setState(() { + _editable = !_editable; + }); + } + @override void initState() { _loadList(); @@ -49,6 +56,13 @@ class _CheckList extends State { 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 { 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, ), ); },