1
+ import 'dart:io' ;
2
+
1
3
import 'package:flutter/material.dart' ;
4
+ import 'package:image_picker/image_picker.dart' ;
2
5
import 'package:record/record.dart' ;
6
+ import 'package:todo/Utils/upload_image.dart' ;
7
+ import 'package:todo/config/route/const.dart' ;
3
8
import 'package:todo/config/themes/my_drawing.dart' ;
9
+ import 'package:todo/data/hive/models/task.dart' ;
10
+ import 'package:todo/data/hive/requests/task_request.dart' ;
4
11
import 'package:todo/data/media_query/media_query.dart' ;
5
12
import 'package:todo/data/media_query/space_between.dart' ;
6
13
import 'package:todo/data/model/front/header_model.dart' ;
@@ -25,6 +32,7 @@ class _AddTaskState extends State<AddTask> {
25
32
final record = Record ();
26
33
bool recordAudio = false ;
27
34
String ? audioPath;
35
+ List <String ?> choosePhoto = [];
28
36
29
37
@override
30
38
void initState () {
@@ -63,7 +71,7 @@ class _AddTaskState extends State<AddTask> {
63
71
name = text;
64
72
});
65
73
},
66
- labelText: "Task Name " ,
74
+ labelText: "Task name " ,
67
75
validation: "required" ,
68
76
preIcon: Icons .task,
69
77
),
@@ -79,7 +87,6 @@ class _AddTaskState extends State<AddTask> {
79
87
title: "record" ,
80
88
child: AudioRecorder (
81
89
onStop: (path) {
82
- print ('Recorded file path: $path ' );
83
90
setState (() {
84
91
audioPath = path;
85
92
recordAudio = true ;
@@ -107,7 +114,7 @@ class _AddTaskState extends State<AddTask> {
107
114
note = text;
108
115
});
109
116
},
110
- labelText: "Add a Note " ,
117
+ labelText: "Add a note " ,
111
118
validation: "required" ,
112
119
preIcon: Icons .note,
113
120
),
@@ -117,9 +124,65 @@ class _AddTaskState extends State<AddTask> {
117
124
loading: false ,
118
125
showBoxShadow: false ,
119
126
icon: Icons .image,
120
- onTab: () {} ,
127
+ onTab: () => chooseImageSource () ,
121
128
title: "Add an image" ),
122
129
intermediate (20 ),
130
+ choosePhoto.isNotEmpty
131
+ ? Wrap (
132
+ children: [
133
+ for (int index = 0 ;
134
+ index < choosePhoto.length;
135
+ index++ )
136
+ Padding (
137
+ padding: const EdgeInsets .symmetric (
138
+ vertical: 10.0 , horizontal: 10.0 ),
139
+ child: InkWell (
140
+ onTap: () => Navigator .of (context).pushNamed (
141
+ RouteName .showImage,
142
+ arguments: choosePhoto[index]! ),
143
+ child: Stack (
144
+ alignment: Alignment .topLeft,
145
+ children: [
146
+ ClipRRect (
147
+ borderRadius: BorderRadius .circular (4.0 ),
148
+ child: Image .file (
149
+ File (choosePhoto[index]! ),
150
+ width: 100 ,
151
+ height: 100 ,
152
+ fit: BoxFit .cover,
153
+ ),
154
+ ),
155
+ InkWell (
156
+ onTap: () {
157
+ setState (() {
158
+ choosePhoto.removeAt (index);
159
+ });
160
+ },
161
+ child: Padding (
162
+ padding: const EdgeInsets .symmetric (
163
+ vertical: 3 , horizontal: 3 ),
164
+ child: ClipOval (
165
+ child: Container (
166
+ alignment: Alignment .center,
167
+ width: 25 ,
168
+ height: 25 ,
169
+ color: MyColors .white,
170
+ child: const Icon (
171
+ Icons .clear,
172
+ color: MyColors .red,
173
+ size: 20 ,
174
+ ),
175
+ ),
176
+ ),
177
+ ))
178
+ ],
179
+ ),
180
+ ),
181
+ ),
182
+ ],
183
+ )
184
+ : Container (),
185
+ intermediate (20 ),
123
186
ButtonLoading (
124
187
btnColor: MyColors .primaryDark,
125
188
btnWidth: context.width - 20 ,
@@ -135,9 +198,48 @@ class _AddTaskState extends State<AddTask> {
135
198
);
136
199
}
137
200
201
+ chooseImageSource () async {
202
+ final res = await ModalClass .showModalBottomCustomSheet (
203
+ context: context,
204
+ child: Container (
205
+ color: MyColors .white,
206
+ width: context.width,
207
+ height: 200 ,
208
+ child: Column (
209
+ children: [
210
+ intermediate (20 ),
211
+ ButtonLoading (
212
+ loading: false ,
213
+ showBoxShadow: false ,
214
+ onTab: () => Navigator .of (context).pop ("camera" ),
215
+ title: "Camera" ),
216
+ intermediate (20 ),
217
+ ButtonLoading (
218
+ loading: false ,
219
+ showBoxShadow: false ,
220
+ onTab: () => Navigator .of (context).pop ("gallery" ),
221
+ title: "Gallery" ),
222
+ ],
223
+ )));
224
+ if (res != null && context.mounted) {
225
+ final result = await UploadImage .openImagePicker (
226
+ source: res == "camera" ? ImageSource .camera : ImageSource .gallery,
227
+ context: context);
228
+ if (result != null ) {
229
+ setState (() {
230
+ choosePhoto.add (result.path);
231
+ });
232
+ }
233
+ }
234
+ }
235
+
138
236
save () {
139
- if (formKey.currentState! .validate ()) {
237
+ if (formKey.currentState! .validate () &&
238
+ audioPath != null &&
239
+ choosePhoto.isNotEmpty) {
140
240
print ("1111111111111111111" );
241
+ TaskHiveRequest .addTask (Task (
242
+ taskName: name! , record: audioPath, note: note! , image: choosePhoto));
141
243
} else {
142
244
print ("ajsdhgkjd" );
143
245
}
0 commit comments