Skip to content

Commit d8893e6

Browse files
committed
Add haptics and reduce slide distance
1 parent 2fed8ff commit d8893e6

File tree

5 files changed

+35
-12
lines changed

5 files changed

+35
-12
lines changed

android/app/src/main/AndroidManifest.xml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
22
package="dev.thecodepapaya.audio_chat">
3-
<uses-permission android:name="android.permission.INTERNET"/>
43
<uses-permission android:name="android.permission.RECORD_AUDIO" />
5-
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
4+
<uses-permission android:name="android.permission.VIBRATE" />
65
<application
76
android:label="audio_chat"
87
android:icon="@mipmap/ic_launcher">

lib/src/home_page.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class _HomePageState extends State<HomePage>
2222
super.initState();
2323
controller = AnimationController(
2424
vsync: this,
25-
duration: const Duration(seconds: 1),
25+
duration: const Duration(milliseconds: 600),
2626
);
2727
}
2828

lib/src/widgets/record_button.dart

+25-9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:audio_chat/src/audio_state.dart';
55
import 'package:audio_chat/src/globals.dart';
66
import 'package:audio_chat/src/widgets/flow_shader.dart';
77
import 'package:flutter/material.dart';
8+
import 'package:flutter_vibrate/flutter_vibrate.dart';
89
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
910
import 'package:record/record.dart';
1011

@@ -60,15 +61,15 @@ class _RecordButtonState extends State<RecordButton> {
6061
.animate(
6162
CurvedAnimation(
6263
parent: widget.controller,
63-
curve: const Interval(0.4, 1, curve: Curves.easeIn),
64+
curve: const Interval(0.2, 1, curve: Curves.easeIn),
6465
),
6566
);
6667
lockerAnimation =
6768
Tween<double>(begin: lockerHeight + Globals.defaultPadding, end: 0)
6869
.animate(
6970
CurvedAnimation(
7071
parent: widget.controller,
71-
curve: const Interval(0.2, 0.8, curve: Curves.elasticInOut),
72+
curve: const Interval(0.2, 1, curve: Curves.easeIn),
7273
),
7374
);
7475
}
@@ -143,8 +144,14 @@ class _RecordButtonState extends State<RecordButton> {
143144
mainAxisSize: MainAxisSize.max,
144145
children: [
145146
Text(recordDuration),
147+
const SizedBox(width: size),
146148
FlowShader(
147-
child: const Text("Slide to cancel"),
149+
child: Row(
150+
children: const [
151+
Icon(Icons.keyboard_arrow_left),
152+
Text("Slide to cancel")
153+
],
154+
),
148155
duration: const Duration(seconds: 3),
149156
flowColors: const [Colors.white, Colors.grey],
150157
),
@@ -171,11 +178,13 @@ class _RecordButtonState extends State<RecordButton> {
171178
child: GestureDetector(
172179
behavior: HitTestBehavior.opaque,
173180
onTap: () async {
174-
var filePath = await Record().stop();
181+
Vibrate.feedback(FeedbackType.success);
175182
timer?.cancel();
176183
timer = null;
177184
startTime = null;
178185
recordDuration = "00:00";
186+
187+
var filePath = await Record().stop();
179188
AudioState.files.add(filePath!);
180189
Globals.audioListKey.currentState!
181190
.insertItem(AudioState.files.length - 1);
@@ -232,7 +241,9 @@ class _RecordButtonState extends State<RecordButton> {
232241
debugPrint("onLongPressEnd");
233242
widget.controller.reverse();
234243

235-
if (isCancelled(details.localPosition)) {
244+
if (isCancelled(details.localPosition, context)) {
245+
Vibrate.feedback(FeedbackType.heavy);
246+
236247
timer?.cancel();
237248
timer = null;
238249
startTime = null;
@@ -244,11 +255,15 @@ class _RecordButtonState extends State<RecordButton> {
244255
File(filePath!).delete();
245256
debugPrint("Deleted $filePath");
246257
} else if (checkIsLocked(details.localPosition)) {
258+
Vibrate.feedback(FeedbackType.heavy);
247259
debugPrint("Locked recording");
260+
debugPrint(details.localPosition.dy.toString());
248261
setState(() {
249262
isLocked = true;
250263
});
251264
} else {
265+
Vibrate.feedback(FeedbackType.success);
266+
252267
timer?.cancel();
253268
timer = null;
254269
startTime = null;
@@ -267,6 +282,7 @@ class _RecordButtonState extends State<RecordButton> {
267282
},
268283
onLongPress: () async {
269284
debugPrint("onLongPress");
285+
Vibrate.feedback(FeedbackType.success);
270286
if (await Record().hasPermission()) {
271287
record = Record();
272288
await record.start(
@@ -277,7 +293,7 @@ class _RecordButtonState extends State<RecordButton> {
277293
samplingRate: 44100,
278294
);
279295
startTime = DateTime.now();
280-
timer = Timer.periodic(const Duration(seconds: 1), (timer) {
296+
timer = Timer.periodic(const Duration(seconds: 1), (_) {
281297
final minDur = DateTime.now().difference(startTime!).inMinutes;
282298
final secDur = DateTime.now().difference(startTime!).inSeconds % 60;
283299
String min = minDur < 10 ? "0$minDur" : minDur.toString();
@@ -292,10 +308,10 @@ class _RecordButtonState extends State<RecordButton> {
292308
}
293309

294310
bool checkIsLocked(Offset offset) {
295-
return (offset.dy < -85 && offset.dy > -135);
311+
return (offset.dy < -35);
296312
}
297313

298-
bool isCancelled(Offset offset) {
299-
return (offset.dx < -200);
314+
bool isCancelled(Offset offset, BuildContext context) {
315+
return (offset.dx < -(MediaQuery.of(context).size.width * 0.3));
300316
}
301317
}

pubspec.lock

+7
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ packages:
102102
description: flutter
103103
source: sdk
104104
version: "0.0.0"
105+
flutter_vibrate:
106+
dependency: "direct main"
107+
description:
108+
name: flutter_vibrate
109+
url: "https://pub.dartlang.org"
110+
source: hosted
111+
version: "1.1.0"
105112
flutter_web_plugins:
106113
dependency: transitive
107114
description: flutter

pubspec.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ dependencies:
3434
permission_handler: ^8.1.6
3535
path_provider: ^2.0.5
3636
record: ^3.0.0
37+
flutter_vibrate: ^1.1.0
3738

3839
# The following adds the Cupertino Icons font to your application.
3940
# Use with the CupertinoIcons class for iOS style icons.

0 commit comments

Comments
 (0)