Example of Implement Vibration Alert in Flutter Android iOS App

Hello friends, In today’s tutorial we would learn about Vibration Alert in flutter. Vibration alert is used in communication devices like mobile phones and pagers to notify the user when a incoming message or call came. In flutter we can use the Vibration PUB package to implement various type of vibration. I have tested this application in real android device and its working fine in real device. But I don’t have real iOS mobile phone so I was unable to check this project in real iOS device. But It works fine in iOS device. So in this tutorial we would learn about Example of Implement Vibration Alert in Flutter Android iOS App.

Contents in this project Example of Implement Vibration Alert in Flutter Android iOS App :-

1. First of all we have to install the Vibration Pub package in our flutter project. To do that open your flutter project’s pubspec.yaml file and add vibration: ^1.7.3 under dependencies block. For better understanding I’m putting my project’s pubspec.yaml file .

Source Code of my pubspec.yaml file :-

2. Now we have to download and install above added package. So open your project location in Command Prompt or Terminal and execute flutter pub get command.

3. Now this step is for Android Users only. To use Vibration in Android devices we have to manually add Vibration permission in AndroidManifest.xml file. So Goto Your_Flutter_Project -> android -> app -> src -> main -> AndroidManifest.xml file. Open the file in any Text editor. I’m using Visual Studio Code editor and put below permission inside it.

Source code of my AndroidManifest.xml file :-

4. Now all the installation process has been done. Next step is to start the coding for application. Open your project’s main.dart file and import material.dart and vibration.dart package.

5. Create our void main runApp() method and here we would call our main MyApp class.

6. Creating our main class MyApp extends StatelessWidget .

7. Creating Widget Build area -> MaterialApp -> Scaffold widget -> Body area -> Column widget .

8. Creating 3 Container widget, Each widget has ElevatedButton.icon() widget. Now on the onPressed event we would call Vibration.vibrate(), Vibration.vibrate(duration: 1000) and Vibration.vibrate( pattern: [ 500, 1000, 500, 2000, 500, 3000, 500, 500 ], ) method. Here 1000 is equal to 1 Second.

9. Complete source code for main.dart file :-

Screenshot :-

Example of Implement Vibration Alert in Flutter Android iOS App

Leave a Reply

Your email address will not be published.