85 lines
2.3 KiB
Dart
85 lines
2.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:happy_camper_proto/preplist.dart';
|
|
import 'package:happy_camper_proto/task.dart';
|
|
|
|
class ListPage extends StatefulWidget {
|
|
const ListPage({super.key, required this.list});
|
|
|
|
final Preplist list;
|
|
|
|
@override
|
|
State<StatefulWidget> createState() => _ListPageState();
|
|
}
|
|
|
|
class _ListPageState extends State<ListPage> {
|
|
late Preplist list;
|
|
|
|
void _showAddItem() async {
|
|
var item = await showDialog(
|
|
context: context,
|
|
builder: (context) {
|
|
GlobalKey<FormState> formKey = GlobalKey();
|
|
TextEditingController inputController = TextEditingController();
|
|
|
|
return AlertDialog(
|
|
title: const Text("Add item"),
|
|
content: Form(
|
|
key: formKey,
|
|
child: TextFormField(
|
|
controller: inputController,
|
|
decoration: const InputDecoration(hintText: "Task"),
|
|
)),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () {
|
|
Navigator.of(context).pop(inputController.text);
|
|
},
|
|
child: const Text("Add"))
|
|
],
|
|
);
|
|
});
|
|
setState(() {
|
|
list.tasks.add(Task(text: item));
|
|
});
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
list = widget.list;
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text(list.name),
|
|
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
|
),
|
|
body: ListView.builder(
|
|
itemCount: list.tasks.length,
|
|
itemBuilder: (context, index) {
|
|
Task task = list.tasks[index];
|
|
return ListTile(
|
|
title: Text(task.text),
|
|
leading: IconButton(
|
|
icon: Icon(task.complete
|
|
? Icons.check_box_outlined
|
|
: Icons.check_box_outline_blank),
|
|
onPressed: () {
|
|
setState(() {
|
|
task.complete = (!task.complete);
|
|
});
|
|
},
|
|
));
|
|
},
|
|
),
|
|
floatingActionButton: FloatingActionButton(
|
|
shape: const CircleBorder(),
|
|
onPressed: _showAddItem,
|
|
child: const Icon(Icons.add),
|
|
),
|
|
);
|
|
}
|
|
}
|