@@ -18,6 +18,8 @@ class _CreateTaskState extends State<CreateTask> {
18
18
DateTime tempDate;
19
19
TimeOfDay tempTime;
20
20
MaterialLocalizations localizations;
21
+ HiveDb database = locator <HiveDb >();
22
+
21
23
List <DropdownMenuItem <String >> dropdownList = [
22
24
DropdownMenuItem (
23
25
child: Text ("Daily" ),
@@ -40,7 +42,7 @@ class _CreateTaskState extends State<CreateTask> {
40
42
"Period" : myChoice,
41
43
};
42
44
if (myChoice == "Daily" ) data["Time" ] = timeCon.text;
43
- return await locator < HiveDb >() .addTask (data);
45
+ return await database .addTask (data);
44
46
}
45
47
46
48
@override
@@ -58,143 +60,107 @@ class _CreateTaskState extends State<CreateTask> {
58
60
await saveTask ().then ((value) {
59
61
if (value) {
60
62
print ("Successful" );
61
- Navigator .pop (context);
63
+ Navigator .pop (context, true );
62
64
}
63
65
});
64
66
},
65
67
child: Icon (
66
68
Icons .done,
67
69
size: 36 ,
68
70
)),
69
- body: Column (
70
- mainAxisSize: MainAxisSize .max,
71
- children: [
72
- SizedBox (
73
- height: 25 ,
74
- ),
75
- DropdownButton <String >(
76
- hint: Text ("Choice Time Period" ),
77
- value: myChoice,
78
- items: dropdownList,
79
- onChanged: (choice) {
80
- setState (() {
81
- myChoice = choice;
82
- });
83
- }),
84
- SizedBox (
85
- height: 25 ,
86
- ),
87
- Padding (
88
- padding: const EdgeInsets .all (8.0 ),
89
- child: Card (
90
- shape: RoundedRectangleBorder (
91
- borderRadius: BorderRadius .circular (20.0 )),
92
- child: Padding (
93
- padding: const EdgeInsets .all (16.0 ),
94
- child: ListTile (
95
- title: TextField (
96
- controller: nameCon,
97
- decoration: InputDecoration (
98
- border: OutlineInputBorder (),
99
- labelText: 'Task Name' ,
100
- labelStyle: TextStyle (fontSize: 20 ),
101
- hintText: 'Enter a task name' ),
102
- ),
103
- ),
104
- ),
71
+ body: SingleChildScrollView (
72
+ child: Column (
73
+ children: [
74
+ SizedBox (
75
+ height: MediaQuery .of (context).size.height * 0.2 ,
105
76
),
106
- ),
107
- SizedBox (
108
- height: 25 ,
109
- ),
110
- /*
111
- Padding(
112
- padding: const EdgeInsets.all(8.0),
113
- child: GestureDetector(
114
- onTap: () async {
115
- final datePick = await showDatePicker(
116
- context: context,
117
- initialDate: tempDate ?? DateTime.now(),
118
- firstDate: DateTime(DateTime.now().year),
119
- lastDate: DateTime(DateTime.now().year + 1),
120
- selectableDayPredicate: (DateTime currentDate) {
121
- if (currentDate.day >= DateTime.now().day &&
122
- currentDate.month >= DateTime.now().month) {
123
- return true;
124
- } else
125
- return false;
126
- });
127
- if (datePick != null) {
128
- setState(() {
129
- tempDate = datePick;
130
- dateCon.text =
131
- "${datePick.day}/${datePick.month}/${datePick.year}";
132
- });
133
- }
134
- },
135
- child: Card(
136
- shape: RoundedRectangleBorder(
137
- borderRadius: BorderRadius.circular(20.0)),
138
- child: Padding(
139
- padding: const EdgeInsets.all(16.0),
140
- child: ListTile(
141
- trailing: Icon(Icons.date_range),
142
- title: TextField(
143
- controller: dateCon,
144
- enabled: false,
145
- decoration: InputDecoration(
146
- labelStyle: TextStyle(fontSize: 20),
147
- hintText: 'Date not set'),
148
- ),
149
- ),
150
- ),
151
- ),
77
+ periodSelection (),
78
+ SizedBox (
79
+ height: 25 ,
152
80
),
153
- ),
154
- SizedBox(
155
- height: 25,
156
- ),
157
- */
158
- Visibility (
159
- visible: myChoice == "Daily" ? true : false ,
160
- child: Padding (
161
- padding: const EdgeInsets .all (8.0 ),
162
- child: GestureDetector (
163
- onTap: () async {
164
- await showTimePicker (
165
- context: context,
166
- initialTime: tempTime ?? TimeOfDay (hour: 12 , minute: 00 ),
167
- ).then ((timePick) {
168
- if (timePick != null ) {
169
- tempTime = timePick;
170
- setState (() {
171
- timeCon.text =
172
- localizations.formatTimeOfDay (timePick);
173
- });
174
- }
175
- });
176
- },
177
- child: Card (
178
- shape: RoundedRectangleBorder (
179
- borderRadius: BorderRadius .circular (20.0 )),
180
- child: Padding (
181
- padding: const EdgeInsets .all (16.0 ),
182
- child: ListTile (
183
- trailing: Icon (Icons .watch_later),
184
- title: TextField (
185
- controller: timeCon,
186
- enabled: false ,
187
- decoration: InputDecoration (
188
- labelStyle: TextStyle (fontSize: 20 ),
189
- hintText: 'Time not set' ),
190
- ),
191
- ),
192
- ),
193
- ),
81
+ taskNameTextField (),
82
+ SizedBox (
83
+ height: 25 ,
84
+ ),
85
+ timePicker (context),
86
+ ],
87
+ ),
88
+ ),
89
+ ),
90
+ );
91
+ }
92
+
93
+ DropdownButton <String > periodSelection () {
94
+ return DropdownButton <String >(
95
+ hint: Text ("Choice Time Period" ),
96
+ value: myChoice,
97
+ items: dropdownList,
98
+ onChanged: (choice) {
99
+ setState (() {
100
+ myChoice = choice;
101
+ });
102
+ });
103
+ }
104
+
105
+ Widget timePicker (BuildContext context) {
106
+ return Visibility (
107
+ visible: myChoice == "Daily" ? true : false ,
108
+ child: Padding (
109
+ padding: const EdgeInsets .all (8.0 ),
110
+ child: GestureDetector (
111
+ onTap: () async {
112
+ await showTimePicker (
113
+ context: context,
114
+ initialTime: tempTime ?? TimeOfDay (hour: 12 , minute: 00 ),
115
+ ).then ((timePick) {
116
+ if (timePick != null ) {
117
+ tempTime = timePick;
118
+ setState (() {
119
+ timeCon.text = localizations.formatTimeOfDay (timePick);
120
+ });
121
+ }
122
+ });
123
+ },
124
+ child: Card (
125
+ shape: RoundedRectangleBorder (
126
+ borderRadius: BorderRadius .circular (20.0 )),
127
+ child: Padding (
128
+ padding: const EdgeInsets .all (16.0 ),
129
+ child: ListTile (
130
+ trailing: Icon (Icons .watch_later),
131
+ title: TextField (
132
+ controller: timeCon,
133
+ enabled: false ,
134
+ decoration: InputDecoration (
135
+ labelStyle: TextStyle (fontSize: 20 ),
136
+ hintText: 'Time not set' ),
194
137
),
195
138
),
196
139
),
197
- ],
140
+ ),
141
+ ),
142
+ ),
143
+ );
144
+ }
145
+
146
+ Padding taskNameTextField () {
147
+ return Padding (
148
+ padding: const EdgeInsets .all (8.0 ),
149
+ child: Card (
150
+ shape:
151
+ RoundedRectangleBorder (borderRadius: BorderRadius .circular (20.0 )),
152
+ child: Padding (
153
+ padding: const EdgeInsets .all (16.0 ),
154
+ child: ListTile (
155
+ title: TextField (
156
+ controller: nameCon,
157
+ decoration: InputDecoration (
158
+ border: OutlineInputBorder (),
159
+ labelText: 'Task Name' ,
160
+ labelStyle: TextStyle (fontSize: 20 ),
161
+ hintText: 'Enter a task name' ),
162
+ ),
163
+ ),
198
164
),
199
165
),
200
166
);
0 commit comments