detail page item add dialog
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
class Item {
|
class Item {
|
||||||
final int id;
|
final int? id;
|
||||||
final String ownerId;
|
final String ownerId;
|
||||||
String title;
|
String title;
|
||||||
String description;
|
String description;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import 'package:briessenchecker/models/checklist.dart';
|
import 'package:briessenchecker/models/checklist.dart';
|
||||||
|
import 'package:briessenchecker/models/listitem.dart';
|
||||||
import 'package:briessenchecker/services/checklist_provider.dart';
|
import 'package:briessenchecker/services/checklist_provider.dart';
|
||||||
import 'package:briessenchecker/services/dbhelper.dart';
|
import 'package:briessenchecker/services/dbhelper.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@@ -6,6 +7,7 @@ import 'package:provider/provider.dart';
|
|||||||
|
|
||||||
class DetailChecklistPage extends StatefulWidget {
|
class DetailChecklistPage extends StatefulWidget {
|
||||||
const DetailChecklistPage({super.key});
|
const DetailChecklistPage({super.key});
|
||||||
|
|
||||||
static const routeName = '/detail';
|
static const routeName = '/detail';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -13,44 +15,98 @@ class DetailChecklistPage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _DetailChecklistPageState extends State<DetailChecklistPage> {
|
class _DetailChecklistPageState extends State<DetailChecklistPage> {
|
||||||
late final ChecklistProvider checklistProvider;
|
late Future<Checklist> _checklistFuture;
|
||||||
late Future<Checklist> checklistFuture;
|
late final ChecklistProvider _checklistProvider;
|
||||||
|
int? _selectedItemId;
|
||||||
@override
|
late Checklist _currentChecklist;
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
checklistProvider = Provider.of<ChecklistProvider>(context, listen: false);
|
|
||||||
checklistFuture =
|
|
||||||
DbHelper.getChecklistById(checklistProvider.selectedChecklistId!);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
super.dispose();
|
super.dispose();
|
||||||
checklistProvider.updateSelectedChecklist(null, silent: true);
|
_checklistProvider.updateSelectedChecklist(null, silent: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
void initState() {
|
||||||
return Scaffold(
|
super.initState();
|
||||||
body: FutureBuilder(
|
_checklistProvider = Provider.of<ChecklistProvider>(context, listen: false);
|
||||||
future: checklistFuture,
|
_checklistFuture = DbHelper.getChecklistById(1);
|
||||||
builder: _futureBuilder,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _futureBuilder(
|
Widget _futureBuilder(
|
||||||
BuildContext context, AsyncSnapshot<Checklist> snapshot) {
|
BuildContext context, AsyncSnapshot<Checklist> snapshot) {
|
||||||
if (snapshot.hasData) {
|
if (snapshot.hasData) {
|
||||||
|
_currentChecklist = snapshot.data!;
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
Text(snapshot.data!.title),
|
Text(_currentChecklist.title),
|
||||||
Text(snapshot.data!.description),
|
Text(_currentChecklist.description),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return const CircularProgressIndicator();
|
return const CircularProgressIndicator();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _addItemTapped() {
|
||||||
|
showDialog(context: context, builder: _addItemDialog);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _addItemDialog(BuildContext context) {
|
||||||
|
TextEditingController titleCon = TextEditingController();
|
||||||
|
TextEditingController descCon = TextEditingController();
|
||||||
|
if (_selectedItemId != null) {
|
||||||
|
final item = _currentChecklist.items.elementAt(_selectedItemId!);
|
||||||
|
titleCon.text = item.title;
|
||||||
|
descCon.text = item.description;
|
||||||
|
}
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text('additem'),
|
||||||
|
content: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
TextFormField(
|
||||||
|
controller: titleCon,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
label: Text('Title'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
TextFormField(
|
||||||
|
controller: descCon,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
label: Text('Description'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
_itemSaved(titleCon.text, descCon.text);
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
child: const Text('save'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
body: FutureBuilder(
|
||||||
|
future: _checklistFuture,
|
||||||
|
builder: _futureBuilder,
|
||||||
|
),
|
||||||
|
floatingActionButton: FloatingActionButton(
|
||||||
|
onPressed: _addItemTapped,
|
||||||
|
child: const Icon(Icons.add),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _itemSaved(String title, String description) {
|
||||||
|
DbHelper.addOrUpdateItem(_checklistProvider.selectedChecklistId!, title,
|
||||||
|
description, _selectedItemId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'package:flutter_dotenv/flutter_dotenv.dart';
|
|||||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||||
import '../assets/example_data.dart' as ed;
|
import '../assets/example_data.dart' as ed;
|
||||||
import '../models/checklist.dart';
|
import '../models/checklist.dart';
|
||||||
|
import '../models/listitem.dart';
|
||||||
|
|
||||||
class DbHelper {
|
class DbHelper {
|
||||||
static late final SupabaseClient _client;
|
static late final SupabaseClient _client;
|
||||||
@@ -38,6 +39,11 @@ class DbHelper {
|
|||||||
return ed.checklists.first;
|
return ed.checklists.first;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<void> addOrUpdateItem(
|
||||||
|
int checklistId, String title, String description, int? itemId) async {
|
||||||
|
// TODO implement addOrUpdateItem
|
||||||
|
}
|
||||||
|
|
||||||
static Stream<AuthState> get authChangeEventStream =>
|
static Stream<AuthState> get authChangeEventStream =>
|
||||||
_client.auth.onAuthStateChange;
|
_client.auth.onAuthStateChange;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user