Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'package:fluttertodo/models/task.dart';
- class AddTask extends StatefulWidget {
- final Function(Task) addTask;
- const AddTask(this.addTask, {super.key});
- @override
- _AddTaskState createState() {
- return _AddTaskState();
- }
- }
- class _AddTaskState extends State<AddTask> {
- @override
- Widget build(BuildContext context) {
- Widget buildTextField(String hint, TextEditingController controller) {
- return Container(
- margin: const EdgeInsets.all(4),
- child: TextField(
- decoration: InputDecoration(
- labelText: hint,
- border: const OutlineInputBorder(
- borderSide: BorderSide(
- color: Colors.black38,
- ),
- ),
- ),
- controller: controller,
- ),
- );
- }
- var titleController = TextEditingController();
- var bodyController = TextEditingController();
- return Container(
- padding: const EdgeInsets.all(8),
- height: 350,
- width: 400,
- child: SingleChildScrollView(
- child: Column(
- children: [
- const Text(
- 'Add New Task',
- style: TextStyle(
- fontWeight: FontWeight.bold,
- fontSize: 32,
- color: Colors.blueGrey,
- ),
- ),
- buildTextField('Title', titleController),
- buildTextField('Body', bodyController),
- ElevatedButton(
- onPressed: () {
- final task = Task(titleController.text, bodyController.text);
- widget.addTask(task);
- Navigator.of(context).pop(task);
- },
- child: const Text('Add Task'),
- ),
- ],
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement