Detail page with actual data from db
This commit is contained in:
@@ -63,6 +63,7 @@ class _DashboardPageState extends State<DashboardPage> {
|
|||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(cl.title == '' ? 'Unnamed ${cl.id}' : cl.title),
|
title: Text(cl.title == '' ? 'Unnamed ${cl.id}' : cl.title),
|
||||||
subtitle: Text(cl.description),
|
subtitle: Text(cl.description),
|
||||||
|
onTap: () => _onListEntryTapped(cl),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,4 +73,9 @@ class _DashboardPageState extends State<DashboardPage> {
|
|||||||
});
|
});
|
||||||
Navigator.of(context).pushNamed(DetailChecklistPage.routeName);
|
Navigator.of(context).pushNamed(DetailChecklistPage.routeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _onListEntryTapped(Checklist cl) {
|
||||||
|
checklistProvider.updateSelectedChecklist(cl.id, silent: true);
|
||||||
|
Navigator.of(context).pushNamed(DetailChecklistPage.routeName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ class DetailChecklistPage extends StatefulWidget {
|
|||||||
class _DetailChecklistPageState extends State<DetailChecklistPage> {
|
class _DetailChecklistPageState extends State<DetailChecklistPage> {
|
||||||
late Future<Checklist> _checklistFuture;
|
late Future<Checklist> _checklistFuture;
|
||||||
late final ChecklistProvider _checklistProvider;
|
late final ChecklistProvider _checklistProvider;
|
||||||
int? _selectedItemId;
|
|
||||||
late Checklist _currentChecklist;
|
late Checklist _currentChecklist;
|
||||||
|
int? _selectedItemId;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
@@ -30,19 +30,23 @@ class _DetailChecklistPageState extends State<DetailChecklistPage> {
|
|||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_checklistProvider = Provider.of<ChecklistProvider>(context, listen: false);
|
_checklistProvider = Provider.of<ChecklistProvider>(context, listen: false);
|
||||||
_checklistFuture = DbHelper.getChecklistById(1);
|
_checklistFuture =
|
||||||
|
DbHelper.getChecklistById(_checklistProvider.selectedChecklistId!);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _futureBuilder(
|
Widget _futureBuilder(
|
||||||
BuildContext context, AsyncSnapshot<Checklist> snapshot) {
|
BuildContext context, AsyncSnapshot<Checklist> snapshot) {
|
||||||
if (snapshot.hasData) {
|
if (snapshot.hasData) {
|
||||||
_currentChecklist = snapshot.data!;
|
_currentChecklist = snapshot.data!;
|
||||||
|
String title = _currentChecklist.title;
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
Text(_currentChecklist.title),
|
Text(title == '' ? 'Unnamed ${_currentChecklist.id}' : title),
|
||||||
Text(_currentChecklist.description),
|
Text(_currentChecklist.description),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
} else if (snapshot.hasError) {
|
||||||
|
return Text(snapshot.error.toString());
|
||||||
} else {
|
} else {
|
||||||
return const CircularProgressIndicator();
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@@ -104,9 +113,4 @@ class _DetailChecklistPageState extends State<DetailChecklistPage> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _itemSaved(String title, String description) {
|
|
||||||
DbHelper.addOrUpdateItem(_checklistProvider.selectedChecklistId!, title,
|
|
||||||
description, _selectedItemId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,19 @@ class DbHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Future<Checklist> getChecklistById(int id) async {
|
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(
|
static Future<void> addOrUpdateItem(
|
||||||
|
|||||||
Reference in New Issue
Block a user