vibrate 0.0.4

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 89

Vibrate

pub package

A Flutter plugin to vibrate the device. This uses all the current Haptic Feedback APIs from Apple and provides similar feedback on Android.

Usage

To use this plugin, add vibrate as a dependency in your pubspec.yaml file.

Make sure you add the following permissions to your Android Manifest

<uses-permission android:name="android.permission.VIBRATE"/>

Usage

// Import package
import 'package:vibrate/vibrate.dart';

Vibration

// Check if the device can vibrate
bool canVibrate = await Vibrate.canVibrate;

// Vibrate
// Vibration duration is a constant 500ms because
// it cannot be set to a specific duration on iOS.
Vibrate.vibrate();

// Vibrate with pauses between each vibration
final Iterable<Duration> pauses = [
    const Duration(milliseconds: 500),
    const Duration(milliseconds: 1000),
    const Duration(milliseconds: 500),
];
// vibrate - sleep 0.5s - vibrate - sleep 1s - vibrate - sleep 0.5s - vibrate
Vibrate.vibrateWithPauses(pauses);

Haptic Feedback

// Choose from any of these available methods
enum FeedbackType {
  success,
  error,
  warning,
  selection,
  impact,
  heavy,
  medium,
  light
}

var _type = FeedbackType.impact;
Vibrate.feedback(_type);

Documentation

Android

https://developer.android.com/reference/android/view/HapticFeedbackConstants

iOS

https://developer.apple.com/design/human-interface-guidelines/ios/user-interaction/feedback/

[0.0.4] - August 22nd, 2018

  • add compatibility for Dart 2 sdk in pubspec.yaml

[0.0.3] - July 10th, 2018

  • haptic Feedback for iOS and Android

[0.0.2] - January 26th, 2018

  • added vibrateWithPauses(Iterable<Duration> pauses)

[0.0.1] - January 24th, 2018

  • vibrate() and canVibrate() implemented on iOS and Android

example/lib/main.dart

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

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  bool _canVibrate = true;
  final Iterable<Duration> pauses = [
    const Duration(milliseconds: 500),
    const Duration(milliseconds: 1000),
    const Duration(milliseconds: 500),
  ];

  @override
  initState() {
    super.initState();
    init();
  }

  init() async {
    bool canVibrate = await Vibrate.canVibrate;
    setState(() {
      _canVibrate = canVibrate;
      _canVibrate
          ? print("This device can vibrate")
          : print("This device cannot vibrate");
    });
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(title: new Text('Haptic Feedback Example')),
        body: new Center(
          child: new Column(children: <Widget>[
            new ListTile(
              title: new Text("Vibrate"),
              leading: new Icon(Icons.vibration, color: Colors.teal),
              onTap: !_canVibrate
                  ? null
                  : () {
                      Vibrate.vibrate();
                    },
            ),
            new ListTile(
              title: new Text("Vibrate with Pauses"),
              leading: new Icon(Icons.vibration, color: Colors.brown),
              onTap: !_canVibrate
                  ? null
                  : () {
                      Vibrate.vibrateWithPauses(pauses);
                    },
            ),
            new Divider(height: 1.0),
            new ListTile(
              title: new Text("Impact"),
              leading: new Icon(Icons.tap_and_play, color: Colors.orange),
              onTap: !_canVibrate
                  ? null
                  : () {
                      Vibrate.feedback(FeedbackType.impact);
                    },
            ),
            new ListTile(
              title: new Text("Selection"),
              leading: new Icon(Icons.select_all, color: Colors.blue),
              onTap: !_canVibrate
                  ? null
                  : () {
                      Vibrate.feedback(FeedbackType.selection);
                    },
            ),
            new ListTile(
              title: new Text("Success"),
              leading: new Icon(Icons.check, color: Colors.green),
              onTap: !_canVibrate
                  ? null
                  : () {
                      Vibrate.feedback(FeedbackType.success);
                    },
            ),
            new ListTile(
              title: new Text("Warning"),
              leading: new Icon(Icons.warning, color: Colors.red),
              onTap: !_canVibrate
                  ? null
                  : () {
                      Vibrate.feedback(FeedbackType.warning);
                    },
            ),
            new ListTile(
              title: new Text("Error"),
              leading: new Icon(Icons.error, color: Colors.red),
              onTap: !_canVibrate
                  ? null
                  : () {
                      Vibrate.feedback(FeedbackType.error);
                    },
            ),
            new Divider(height: 1.0),
            new ListTile(
              title: new Text("Heavy"),
              leading:
                  new Icon(Icons.notification_important, color: Colors.red),
              onTap: !_canVibrate
                  ? null
                  : () {
                      Vibrate.feedback(FeedbackType.heavy);
                    },
            ),
            new ListTile(
              title: new Text("Medium"),
              leading:
                  new Icon(Icons.notification_important, color: Colors.green),
              onTap: !_canVibrate
                  ? null
                  : () {
                      Vibrate.feedback(FeedbackType.medium);
                    },
            ),
            new ListTile(
              title: new Text("Light"),
              leading: new Icon(Icons.notification_important,
                  color: Colors.yellow[700]),
              onTap: !_canVibrate
                  ? null
                  : () {
                      Vibrate.feedback(FeedbackType.light);
                    },
            ),
          ]),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  vibrate: ^0.0.4

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:vibrate/vibrate.dart';
  
Version Uploaded Documentation Archive
0.0.4 Aug 22, 2018 Go to the documentation of vibrate 0.0.4 Download vibrate 0.0.4 archive
0.0.3 Jul 10, 2018 Go to the documentation of vibrate 0.0.3 Download vibrate 0.0.3 archive
0.0.2 Jan 26, 2018 Go to the documentation of vibrate 0.0.2 Download vibrate 0.0.2 archive
0.0.1 Jan 24, 2018 Go to the documentation of vibrate 0.0.1 Download vibrate 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
91
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
89
Learn more about scoring.

We analyzed this package on Oct 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.4
  • Flutter: 0.9.5

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Maintenance suggestions

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Package is pre-v0.1 release. (-10 points)

While there is nothing inherently wrong with versions of 0.0.*, it usually means that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8