128 lines
3.4 KiB
Dart
128 lines
3.4 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../database/habit.dart';
|
|
|
|
// save button + speichern durch enter
|
|
|
|
class AddHabitPopup extends StatefulWidget {
|
|
//final Function? onHabitAdded;
|
|
//final Habit todo;
|
|
final void Function(String, String) onSubmit;
|
|
|
|
@override
|
|
_AddHabitPopupState createState() => _AddHabitPopupState();
|
|
|
|
const AddHabitPopup({
|
|
Key? key,
|
|
//this.todo,
|
|
required this.onSubmit,
|
|
}) : super(key: key);
|
|
}
|
|
|
|
|
|
class _AddHabitPopupState extends State<AddHabitPopup> {
|
|
final titleController = TextEditingController();
|
|
final subtitleController = TextEditingController();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
titleController.text = "default";
|
|
subtitleController.text = "default";
|
|
}
|
|
|
|
String title = '';
|
|
String subtitle = '';
|
|
final _formKey = GlobalKey<FormState>();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AlertDialog(
|
|
title: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
IconButton(
|
|
icon: const Icon(Icons.close, color: Colors.red),
|
|
onPressed: () => Navigator.pop(context),
|
|
),
|
|
const Expanded(
|
|
child: Text(
|
|
'Add task',
|
|
textAlign: TextAlign.center,
|
|
)
|
|
)
|
|
],
|
|
),
|
|
content: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
const Divider(thickness: 3),
|
|
const Text(
|
|
'Tasks start each day as incomplete.\n'
|
|
'Mark a task as done to keep your progress up.\n'
|
|
'CREATE YOUR OWN:',
|
|
textAlign: TextAlign.start,
|
|
style: TextStyle(
|
|
color: Colors.black,
|
|
fontWeight: FontWeight.bold,
|
|
fontFamily: 'Arial',
|
|
fontSize: 14,
|
|
),
|
|
),
|
|
|
|
Form(
|
|
key: _formKey,
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: <Widget>[
|
|
TextFormField(
|
|
autofocus: true,
|
|
controller: titleController,
|
|
decoration: const InputDecoration(
|
|
icon: Icon(Icons.title),
|
|
labelText: "Title",
|
|
hintText: "Enter task title",
|
|
),
|
|
//keyboardType: TextInputType.text,
|
|
validator: (value) =>
|
|
value != null && value.isEmpty ? "Please enter a title" : null
|
|
),
|
|
|
|
TextFormField(
|
|
controller: subtitleController,
|
|
decoration: const InputDecoration(
|
|
icon: Icon(Icons.description),
|
|
labelText: "Description",
|
|
hintText: "Describe how you plan to achieve your goal",
|
|
),
|
|
validator: (value) =>
|
|
value != null && value.isEmpty ? "Please enter a subtitle" : null
|
|
),
|
|
],
|
|
),
|
|
),
|
|
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
if (_formKey.currentState!.validate()) {
|
|
widget.onSubmit(titleController.text,subtitleController.text);
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(
|
|
content: Text('Form saved!'),
|
|
),
|
|
);
|
|
}
|
|
},
|
|
child: const Text('Save'),
|
|
)
|
|
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|