import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:cpd/model/habit_list.dart'; // save button + speichern durch enter class AddHabitPopup extends StatefulWidget { @override _AddHabitPopupState createState() => _AddHabitPopupState(); } class _AddHabitPopupState extends State { String title = ''; String subtitle = ''; final _formKey = GlobalKey(); @override Widget build(BuildContext context) { return AlertDialog( title: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ IconButton( icon: const Icon(Icons.close, color: Colors.red), onPressed: () { Navigator.of(context).pop(); }, ), Expanded(child: const Text( 'Add task', textAlign: TextAlign.center, ) ) ], ), content: Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ 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: [ TextFormField( decoration: const InputDecoration( icon: Icon(Icons.title), labelText: "Title", hintText: "Enter task title", ), keyboardType: TextInputType.text, validator: (String? value) { return (value == null || value.trim().isEmpty) ? "Please enter a title" : null; }, ), TextFormField( decoration: const InputDecoration( icon: Icon(Icons.description), labelText: "Description", hintText: "Describe how you plan to achieve your goal", ), keyboardType: TextInputType.text, validator: (String? value) { return (value == null || value.trim().isEmpty) ? "Please enter a title" : null; }, ), SizedBox(height: 16.0), ElevatedButton( onPressed: () { if (_formKey.currentState!.validate()) { // Save the form data here ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text('Form saved!'), ), ); } }, child: Text('Save'), ) ], ), ), ], ), ); } }