See and change description of checklist
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -179,16 +179,9 @@ class _DetailChecklistPageState extends State<DetailChecklistPage> {
|
||||
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<DetailChecklistPage> {
|
||||
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<DetailChecklistPage> {
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,6 +86,13 @@ class DbHelper {
|
||||
.update({'title': title}).eq('id', id);
|
||||
}
|
||||
|
||||
static Future<void> updateChecklistDescription(
|
||||
int id, String description) async {
|
||||
await _client
|
||||
.from(checklistsTableName)
|
||||
.update({'description': description}).eq('id', id);
|
||||
}
|
||||
|
||||
/// returns id of newly created checklist
|
||||
static Future<int> addOrUpdateChecklist(Checklist? checklist) async {
|
||||
final ownerId = _client.auth.currentSession!.user.id;
|
||||
|
||||
Reference in New Issue
Block a user