diff --git a/lib/models/checklist.dart b/lib/models/checklist.dart index 6e41e64..42b0de6 100644 --- a/lib/models/checklist.dart +++ b/lib/models/checklist.dart @@ -1,10 +1,13 @@ class Checklist { final int id; final String ownerId; - String title; + String _title; String description; final DateTime createdTime; + String get title => _title == '' ? 'Unnamed $id' : _title; + Checklist( - this.id, this.ownerId, this.title, this.description, this.createdTime); + this.id, this.ownerId, String title, this.description, this.createdTime) + : _title = title; } diff --git a/lib/pages/detail_checklist_page.dart b/lib/pages/detail_checklist_page.dart index 9abf21e..8761a83 100644 --- a/lib/pages/detail_checklist_page.dart +++ b/lib/pages/detail_checklist_page.dart @@ -179,16 +179,9 @@ class _DetailChecklistPageState extends State { if (snapshot.hasData) { _items = DbHelper.resToItemList(snapshot.data!); } - return Column( - children: [ - Text(_checklist!.description), - Expanded( - child: ListView.builder( - itemCount: _items.length, - itemBuilder: _itemListBuilder, - ), - ), - ], + return ListView.builder( + itemCount: _items.length, + itemBuilder: _itemListBuilder, ); } @@ -198,6 +191,9 @@ class _DetailChecklistPageState extends State { appBar: AppBar( title: _pageTitleBuilder, actions: [ + if (!_titleEditMode) + IconButton( + onPressed: _onInfoButtonPressed, icon: const Icon(Icons.info)), if (_titleEditMode) IconButton( onPressed: () => _onTitleChanged( @@ -244,4 +240,36 @@ class _DetailChecklistPageState extends State { await DbHelper.deleteCheckedEntry(_checklist!.id, id!); } } + + void _onInfoButtonPressed() { + TextEditingController desCon = TextEditingController(); + desCon.text = _checklist!.description; + showDialog( + context: context, + builder: (context) => AlertDialog( + title: Text(_checklist!.title), + content: SizedBox( + width: 300, + child: DbHelper.isOwner(_checklist!.ownerId) + ? TextField( + controller: desCon, + maxLines: 5, + decoration: const InputDecoration( + label: Text('Description'), + ), + ) + : Text(_checklist!.description), + ), + actions: [ + TextButton( + onPressed: () => Navigator.of(context).pop(), + child: const Text('Ok'), + ) + ], + ), + ).whenComplete(() { + DbHelper.updateChecklistDescription(_checklist!.id, desCon.text); + setState(() => _checklist!.description = desCon.text); + }); + } } diff --git a/lib/services/dbhelper.dart b/lib/services/dbhelper.dart index bd6c606..ae6c48b 100644 --- a/lib/services/dbhelper.dart +++ b/lib/services/dbhelper.dart @@ -86,6 +86,13 @@ class DbHelper { .update({'title': title}).eq('id', id); } + static Future updateChecklistDescription( + int id, String description) async { + await _client + .from(checklistsTableName) + .update({'description': description}).eq('id', id); + } + /// returns id of newly created checklist static Future addOrUpdateChecklist(Checklist? checklist) async { final ownerId = _client.auth.currentSession!.user.id;