@@ -34,6 +34,7 @@ class _RecordButtonState extends State<RecordButton> {
34
34
Timer ? timer;
35
35
String recordDuration = "00:00" ;
36
36
late Record record;
37
+ bool isLocked = false ;
37
38
38
39
@override
39
40
void initState () {
@@ -75,6 +76,7 @@ class _RecordButtonState extends State<RecordButton> {
75
76
@override
76
77
void dispose () {
77
78
record.dispose ();
79
+ timer? .cancel ();
78
80
super .dispose ();
79
81
}
80
82
@@ -84,8 +86,9 @@ class _RecordButtonState extends State<RecordButton> {
84
86
clipBehavior: Clip .none,
85
87
children: [
86
88
lockSlider (),
87
- timerSlider (context ),
89
+ cancelSlider ( ),
88
90
audioButton (),
91
+ if (isLocked) timerLocked (),
89
92
],
90
93
);
91
94
}
@@ -122,7 +125,7 @@ class _RecordButtonState extends State<RecordButton> {
122
125
);
123
126
}
124
127
125
- Widget timerSlider ( BuildContext context ) {
128
+ Widget cancelSlider ( ) {
126
129
return Positioned (
127
130
right: - timerAnimation.value,
128
131
child: Container (
@@ -152,6 +155,58 @@ class _RecordButtonState extends State<RecordButton> {
152
155
);
153
156
}
154
157
158
+ Widget timerLocked () {
159
+ return Positioned (
160
+ right: 0 ,
161
+ child: Container (
162
+ height: size,
163
+ width: timerWidth,
164
+ decoration: BoxDecoration (
165
+ borderRadius: BorderRadius .circular (Globals .borderRadius),
166
+ color: Colors .black,
167
+ ),
168
+ child: Padding (
169
+ padding: const EdgeInsets .only (left: 15 , right: 25 ),
170
+ child: GestureDetector (
171
+ behavior: HitTestBehavior .opaque,
172
+ onTap: () async {
173
+ var filePath = await Record ().stop ();
174
+ AudioState .files.add (filePath! );
175
+ Globals .audioListKey.currentState!
176
+ .insertItem (AudioState .files.length - 1 );
177
+ debugPrint (filePath);
178
+ setState (() {
179
+ isLocked = false ;
180
+ });
181
+ startTime = null ;
182
+ recordDuration = "00:00" ;
183
+ timer? .cancel ();
184
+ },
185
+ child: Row (
186
+ mainAxisAlignment: MainAxisAlignment .spaceBetween,
187
+ mainAxisSize: MainAxisSize .max,
188
+ children: [
189
+ Text (recordDuration),
190
+ FlowShader (
191
+ child: const Text ("Tap lock to stop" ),
192
+ duration: const Duration (seconds: 3 ),
193
+ flowColors: const [Colors .white, Colors .grey],
194
+ ),
195
+ const Center (
196
+ child: FaIcon (
197
+ FontAwesomeIcons .lock,
198
+ size: 18 ,
199
+ color: Colors .green,
200
+ ),
201
+ ),
202
+ ],
203
+ ),
204
+ ),
205
+ ),
206
+ ),
207
+ );
208
+ }
209
+
155
210
Widget audioButton () {
156
211
return GestureDetector (
157
212
child: Transform .scale (
@@ -174,19 +229,25 @@ class _RecordButtonState extends State<RecordButton> {
174
229
onLongPressEnd: (details) async {
175
230
debugPrint ("onLongPressEnd" );
176
231
widget.controller.reverse ();
177
- debugPrint (details.localPosition.toString ());
178
- startTime = null ;
179
- recordDuration = "00:00" ;
180
- timer? .cancel ();
232
+
181
233
if (isCancelled (details.localPosition)) {
234
+ startTime = null ;
235
+ recordDuration = "00:00" ;
236
+ timer? .cancel ();
182
237
debugPrint ("Cancelled recording" );
183
238
var filePath = await record.stop ();
184
239
debugPrint (filePath);
185
240
File (filePath! ).delete ();
186
241
debugPrint ("Deleted $filePath " );
187
- } else if (isLocked (details.localPosition)) {
242
+ } else if (checkIsLocked (details.localPosition)) {
188
243
debugPrint ("Locked recording" );
244
+ setState (() {
245
+ isLocked = true ;
246
+ });
189
247
} else {
248
+ startTime = null ;
249
+ recordDuration = "00:00" ;
250
+ timer? .cancel ();
190
251
var filePath = await Record ().stop ();
191
252
AudioState .files.add (filePath! );
192
253
Globals .audioListKey.currentState!
@@ -224,7 +285,7 @@ class _RecordButtonState extends State<RecordButton> {
224
285
);
225
286
}
226
287
227
- bool isLocked (Offset offset) {
288
+ bool checkIsLocked (Offset offset) {
228
289
return (offset.dy < - 85 && offset.dy > - 135 );
229
290
}
230
291
0 commit comments