Detail page with actual data from db

This commit is contained in:
marcoabat
2023-08-05 17:11:16 +02:00
parent ce57940c21
commit 6f8ee1a6ab
3 changed files with 31 additions and 9 deletions

View File

@@ -63,6 +63,7 @@ class _DashboardPageState extends State<DashboardPage> {
return ListTile(
title: Text(cl.title == '' ? 'Unnamed ${cl.id}' : cl.title),
subtitle: Text(cl.description),
onTap: () => _onListEntryTapped(cl),
);
}
@@ -72,4 +73,9 @@ class _DashboardPageState extends State<DashboardPage> {
});
Navigator.of(context).pushNamed(DetailChecklistPage.routeName);
}
void _onListEntryTapped(Checklist cl) {
checklistProvider.updateSelectedChecklist(cl.id, silent: true);
Navigator.of(context).pushNamed(DetailChecklistPage.routeName);
}
}

View File

@@ -17,8 +17,8 @@ class DetailChecklistPage extends StatefulWidget {
class _DetailChecklistPageState extends State<DetailChecklistPage> {
late Future<Checklist> _checklistFuture;
late final ChecklistProvider _checklistProvider;
int? _selectedItemId;
late Checklist _currentChecklist;
int? _selectedItemId;
@override
void dispose() {
@@ -30,19 +30,23 @@ class _DetailChecklistPageState extends State<DetailChecklistPage> {
void initState() {
super.initState();
_checklistProvider = Provider.of<ChecklistProvider>(context, listen: false);
_checklistFuture = DbHelper.getChecklistById(1);
_checklistFuture =
DbHelper.getChecklistById(_checklistProvider.selectedChecklistId!);
}
Widget _futureBuilder(
BuildContext context, AsyncSnapshot<Checklist> snapshot) {
if (snapshot.hasData) {
_currentChecklist = snapshot.data!;
String title = _currentChecklist.title;
return Column(
children: [
Text(_currentChecklist.title),
Text(title == '' ? 'Unnamed ${_currentChecklist.id}' : title),
Text(_currentChecklist.description),
],
);
} else if (snapshot.hasError) {
return Text(snapshot.error.toString());
} else {
return const CircularProgressIndicator();
}
@@ -91,6 +95,11 @@ class _DetailChecklistPageState extends State<DetailChecklistPage> {
);
}
void _itemSaved(String title, String description) {
DbHelper.addOrUpdateItem(_checklistProvider.selectedChecklistId!, title,
description, _selectedItemId);
}
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -104,9 +113,4 @@ class _DetailChecklistPageState extends State<DetailChecklistPage> {
),
);
}
void _itemSaved(String title, String description) {
DbHelper.addOrUpdateItem(_checklistProvider.selectedChecklistId!, title,
description, _selectedItemId);
}
}

View File

@@ -73,7 +73,19 @@ class DbHelper {
}
static Future<Checklist> getChecklistById(int id) async {
return ed.checklists.first;
final res = await _client
.from(checklistsTableName)
.select<Map<String, dynamic>>()
.eq('id', id)
.single();
return Checklist(
res['id'],
res['ownerId'],
res['title'],
res['description'],
DateTime.parse(res['createdTime']),
[],
);
}
static Future<void> addOrUpdateItem(