-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToDoForm.dart
94 lines (85 loc) · 2.66 KB
/
ToDoForm.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// ignore_for_file: file_names
import 'package:flutter/material.dart';
class ToDoForm extends StatelessWidget {
const ToDoForm(
{Key? key,
this.title = '',
this.description = '',
required this.onChangedTitle,
required this.onChangedDescription,
required this.onChangedTodo})
: super(key: key);
final String title;
final String description;
final ValueChanged<String> onChangedTitle;
final ValueChanged<String> onChangedDescription;
final VoidCallback onChangedTodo;
@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
buildTitle(),
const SizedBox(height: 8.0),
buildDescription(),
const SizedBox(
height: 15.0,
),
buildButton(),
],
);
}
// -------------------------- Widget for Title ---------------------------------
Widget buildTitle() => TextFormField(
maxLines: 1,
initialValue: title,
onChanged: onChangedTitle,
validator: (title) {
if (title!.isEmpty) {
return 'The Title Cannot be Empty';
}
return null;
},
decoration: const InputDecoration(
labelText: "Title",
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(width: 2.0, color: Color(0xff8a2be2)),
),
border: UnderlineInputBorder(),
),
);
// ----------------------------- Widget for Description ----------------------
Widget buildDescription() => TextFormField(
maxLines: 5,
initialValue: description,
onChanged: onChangedDescription,
decoration: const InputDecoration(
labelText: 'Description',
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
width: 2.0,
color: Color(0xff8a2be2),
),
),
border: UnderlineInputBorder(),
),
);
// ---------------------------- Widget for Save Button -----------------------
Widget buildButton() => SizedBox(
width: double.infinity,
child: ElevatedButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.orange),
),
onPressed: onChangedTodo,
child: const Padding(
padding: EdgeInsets.symmetric(vertical: 8.0),
child: Text("Save",
style: TextStyle(
letterSpacing: 1.0,
fontSize: 15,
)),
),
),
);
}