1. Haptic Feedback vs Vibrate
- Haptic Feedback 는 터치 시 잠깐 주는 작은 진동
- Vibrate 는 전화 올 때 오는 큰 진동
2. Haptic Feedback
1) 휴대폰 설정
휴대폰 > 설정 > 소리 및 진동 > 시스템 진동 > 터치 피드백
2) 코드
import 'package:flutter/services.dart';
class ScheduleMain extends StatefulWidget {
const ScheduleMain({Key? key}) : super(key: key);
@override
State<ScheduleMain> createState() => _ScheduleMainState();
}
class _ScheduleMainState extends State<ScheduleMain> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('SigSchedule'),
),
body: ScheduleList(),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {
//설정
HapticFeedback.lightImpact();
},
),
bottomNavigationBar: CustomBottomNavagationBar(),
);
}
}
3) 퍼미션 설정: 불필요
- 아래와 같이 퍼미션 설정을 해 주라는 내용이 있는데 안드로이드 13 기준으로 안 해도 동작함
프로젝트 > android > app > src > main > AndroidManifest.xml
...
<uses-permission android:name="android.permission.VIBRATE" />
...
3. Vibrate
1) 패키지 가져오기
//최신 버전은 1.8.5인데 이 패키지 가져오면 sdk 버전 관련한 에러가 발생해서 낮은 버전으로 진행함
프로젝트 > pubspec.yaml
dependencies:
vibration: ^1.7.7
2) 코드
import 'package:vibration/vibration.dart';
class ScheduleMain extends StatefulWidget {
const ScheduleMain({Key? key}) : super(key: key);
@override
State<ScheduleMain> createState() => _ScheduleMainState();
}
class _ScheduleMainState extends State<ScheduleMain> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('SigSchedule'),
),
body: ScheduleList(),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () => {
showDialog(context: context, builder: (context) {
//설정
Vibration.vibrate(duration: 1000);
}),
},
),
bottomNavigationBar: CustomBottomNavagationBar(),
);
}
}