vibrate 0.0.3

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

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.vibrate(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.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.3

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub 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]
94
Health:
Code health derived from static analysis. [more]
--
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
--
Overall:
Weighted score of the above. [more]
47
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://dart.dev/dart-2#migration.

Maintenance issues and suggestions

Make sure dartdoc successfully runs on your package's source files. (-10 points)

Dependencies were not resolved.