How to make phone vibrate with Flutter

Title is pretty straight forward.

First, import the vibrate package from pub. Also, check out how to set it up.

Create a new dart file and paste this code:

import 'package:flutter/material.dart';
import 'package:vibrate/vibrate.dart';

class VibrateExample extends StatefulWidget {
  _VibrateExampleState createState() => _VibrateExampleState();

class _VibrateExampleState extends State<VibrateExample> {
  bool _canVibrate = false;

  void initState() {

  _checkVibration() async {
    _canVibrate = await Vibrate.canVibrate;

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Vibrate Phone Example')),
      body: Center(
        child: _canVibrate
            ? RaisedButton(
                child: Text("Vibrate Phone"),
                onPressed: () => Vibrate.vibrate())
            : Text("Phone Cannot Vibrate"),

In main.dart:

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  Widget build(BuildContext context) {
    return new MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Code Snippets',
      theme: new ThemeData(primarySwatch:,
      home: new VibrateExample(),

If you have any questions or suggestions kindly use the comment box or you can contact us directly through our contact page below.

Add a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.