Overview of the Vibration plugin
mastervibration plugin provides a unified API for handling device vibration across iOS, Android, and Web platforms in Flutter applications.repository·master·Indexed 43 days ago
https://github.com/benjamindean/flutter_vibrationA Flutter plugin providing cross-platform vibration capabilities for iOS, Android, Web, and OpenHarmony. It offers a unified API to trigger haptic feedback using durations, custom patterns, intensities, and predefined VibrationPreset values. Includes specialized support for OpenHarmony via the vibration_ohos package, allowing for VibrateEffect and VibrateAttribute configurations.
vibration plugin provides a unified API for handling device vibration across iOS, Android, and Web platforms in Flutter applications.vibration_ohos_example project serves as a demonstration application for the vibration_ohos plugin. It provides a starting point for developers to understand how to integrate and use the vibration functionality within a Flutter application targeting OpenHarmony (OHOS).To customize the iOS launch screen, you can either replace the image files directly in the vibration/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/ directory or use Xcode for a more visual approach.
Using Xcode:
open ios/Runner.xcworkspace.Runner/Assets.xcassets.open ios/Runner.xcworkspaceFor OpenHarmony support, add the ohos.permission.VIBRATE permission to your project's module.json5 file.
"requestPermissions": [
{"name" : "ohos.permission.VIBRATE"},
]Add vibration_ohos and the base vibration package to your pubspec.yaml dependencies.
dependencies:
vibration: any
vibration_ohos: anyTo use vibration on the web, ensure you have the vibration package added to your pubspec.yaml. Once added, you can use package:vibration as you would in a standard Flutter project. This package provides the web-specific implementation required for the vibration plugin to function in a browser environment.
dependencies:
vibration: ^latest_versionvibration_platform_interface package is a common platform interface for the vibration package. You do not need to install it separately; it is automatically included as a dependency when you add the vibration package to your project.The project is organized into different versions depending on your target platform:
vibration package.vibration_web package.To use vibration on the OpenHarmony platform, you must add the ohos.permission.VIBRATE permission to your project's module.json5 file.
"requestPermissions": [
{"name" : "ohos.permission.VIBRATE"},
]To use vibration on Android, you must add the VIBRATE permission to your AndroidManifest.xml file.
<uses-permission android:name="android.permission.VIBRATE"/>To use the vibration plugin in your Flutter project, add vibration to your pubspec.yaml dependencies and import the package in your Dart files.
dependencies:
vibration: ^3.1.3import 'package:vibration/vibration.dart';When using the OpenHarmony implementation (vibration_ohos), you can access vibrateEffect and vibrateAttribute by casting the platform instance to VibrationOhos.
(VibrationPlatform.instance as VibrationOhos).vibrate(
vibrateEffect: const VibratePreset(count: 100),
vibrateAttribute: const VibrateAttribute(
usage: 'alarm',
),
);