See and change description of checklist
This commit is contained in:
@@ -1,10 +1,13 @@
|
|||||||
class Checklist {
|
class Checklist {
|
||||||
final int id;
|
final int id;
|
||||||
final String ownerId;
|
final String ownerId;
|
||||||
String title;
|
String _title;
|
||||||
String description;
|
String description;
|
||||||
final DateTime createdTime;
|
final DateTime createdTime;
|
||||||
|
|
||||||
|
String get title => _title == '' ? 'Unnamed $id' : _title;
|
||||||
|
|
||||||
Checklist(
|
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) {
|
if (snapshot.hasData) {
|
||||||
_items = DbHelper.resToItemList(snapshot.data!);
|
_items = DbHelper.resToItemList(snapshot.data!);
|
||||||
}
|
}
|
||||||
return Column(
|
return ListView.builder(
|
||||||
children: [
|
itemCount: _items.length,
|
||||||
Text(_checklist!.description),
|
itemBuilder: _itemListBuilder,
|
||||||
Expanded(
|
|
||||||
child: ListView.builder(
|
|
||||||
itemCount: _items.length,
|
|
||||||
itemBuilder: _itemListBuilder,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,6 +191,9 @@ class _DetailChecklistPageState extends State<DetailChecklistPage> {
|
|||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: _pageTitleBuilder,
|
title: _pageTitleBuilder,
|
||||||
actions: [
|
actions: [
|
||||||
|
if (!_titleEditMode)
|
||||||
|
IconButton(
|
||||||
|
onPressed: _onInfoButtonPressed, icon: const Icon(Icons.info)),
|
||||||
if (_titleEditMode)
|
if (_titleEditMode)
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () => _onTitleChanged(
|
onPressed: () => _onTitleChanged(
|
||||||
@@ -244,4 +240,36 @@ class _DetailChecklistPageState extends State<DetailChecklistPage> {
|
|||||||
await DbHelper.deleteCheckedEntry(_checklist!.id, id!);
|
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);
|
.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
|
/// returns id of newly created checklist
|
||||||
static Future<int> addOrUpdateChecklist(Checklist? checklist) async {
|
static Future<int> addOrUpdateChecklist(Checklist? checklist) async {
|
||||||
final ownerId = _client.auth.currentSession!.user.id;
|
final ownerId = _client.auth.currentSession!.user.id;
|
||||||
|
|||||||
Reference in New Issue
Block a user