diff --git a/lib/pages/dashboard_page.dart b/lib/pages/dashboard_page.dart index e599436..777c3df 100644 --- a/lib/pages/dashboard_page.dart +++ b/lib/pages/dashboard_page.dart @@ -63,6 +63,7 @@ class _DashboardPageState extends State { 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 { }); Navigator.of(context).pushNamed(DetailChecklistPage.routeName); } + + void _onListEntryTapped(Checklist cl) { + checklistProvider.updateSelectedChecklist(cl.id, silent: true); + Navigator.of(context).pushNamed(DetailChecklistPage.routeName); + } } diff --git a/lib/pages/detail_checklist_page.dart b/lib/pages/detail_checklist_page.dart index 980dbc6..96ed754 100644 --- a/lib/pages/detail_checklist_page.dart +++ b/lib/pages/detail_checklist_page.dart @@ -17,8 +17,8 @@ class DetailChecklistPage extends StatefulWidget { class _DetailChecklistPageState extends State { late Future _checklistFuture; late final ChecklistProvider _checklistProvider; - int? _selectedItemId; late Checklist _currentChecklist; + int? _selectedItemId; @override void dispose() { @@ -30,19 +30,23 @@ class _DetailChecklistPageState extends State { void initState() { super.initState(); _checklistProvider = Provider.of(context, listen: false); - _checklistFuture = DbHelper.getChecklistById(1); + _checklistFuture = + DbHelper.getChecklistById(_checklistProvider.selectedChecklistId!); } Widget _futureBuilder( BuildContext context, AsyncSnapshot 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 { ); } + 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 { ), ); } - - void _itemSaved(String title, String description) { - DbHelper.addOrUpdateItem(_checklistProvider.selectedChecklistId!, title, - description, _selectedItemId); - } } diff --git a/lib/services/dbhelper.dart b/lib/services/dbhelper.dart index 1d2e5f3..eda3d96 100644 --- a/lib/services/dbhelper.dart +++ b/lib/services/dbhelper.dart @@ -73,7 +73,19 @@ class DbHelper { } static Future getChecklistById(int id) async { - return ed.checklists.first; + final res = await _client + .from(checklistsTableName) + .select>() + .eq('id', id) + .single(); + return Checklist( + res['id'], + res['ownerId'], + res['title'], + res['description'], + DateTime.parse(res['createdTime']), + [], + ); } static Future addOrUpdateItem(