vibration
v3.1.8A plugin for handling Vibration API on iOS, Android, web and OpenHarmony.
Архив пакета: https://pubdev.letsnova.ru/api/archives/vibration/3.1.8.tar.gz
dart pub add vibrationREADME
Vibration
A plugin for handling Vibration API on iOS, Android, and web. API docs.
Getting Started
-
Add
vibrationto the dependencies section ofpubspec.yaml.dependencies: vibration: ^3.1.3 -
Import package:
import 'package:vibration/vibration.dart';
Methods
hasVibrator
Check if the target device has vibration capabilities. Not required when using other methods.
if (await Vibration.hasVibrator()) {
Vibration.vibrate();
}
hasAmplitudeControl
Check if the target device has the ability to control the vibration amplitude, introduced in Android 8.0 Oreo - false for all earlier API levels.
if (await Vibration.hasAmplitudeControl()) {
Vibration.vibrate(amplitude: 128);
}
hasCustomVibrationsSupport
Check if the device is able to vibrate with a custom duration, pattern or intensity.
May return true even if the device has no vibrator (if you want to check whether the device has a vibrator,
see hasVibrator).
if (await Vibration.hasCustomVibrationsSupport()) {
Vibration.vibrate(duration: 1000);
} else {
Vibration.vibrate();
await Future.delayed(Duration(milliseconds: 500));
Vibration.vibrate();
}
vibrate
Method Arguments
duration: Duration of the vibration in milliseconds. Default is 500ms.pattern: List of integers representing the vibration pattern. Alternates between wait and vibrate durations.repeat: Index in the pattern at which to repeat, or -1 for no repeat. Default is -1.intensities: List of integers representing the vibration intensities for each segment in the pattern.amplitude: Amplitude of the vibration. Range is 1 to 255. Default is -1 (use platform default).sharpness: Sharpness of the vibration. iOS only. Range is 0.0 to 1.0. Default is 0.5.preset: Predefined vibration preset. Overrides other parameters if provided.
With specific duration (for example, 1 second):
Vibration.vibrate(duration: 1000);
Default duration is 500ms.
With specific duration and specific amplitude (if supported):
Vibration.vibrate(duration: 1000, amplitude: 128);
With pattern (wait 500ms, vibrate 1s, wait 500ms, vibrate 2s):
Vibration.vibrate(pattern: [500, 1000, 500, 2000]);
With pattern (wait 500ms, vibrate 1s, wait 500ms, vibrate 2s) at varying intensities (1 - min, 255 - max):
Vibration.vibrate(pattern: [500, 1000, 500, 2000], intensities: [1, 255]);
With vibration presets:
You can use predefined vibration presets for common use cases.
Vibration.vibrate(preset: VibrationPreset.alarm);
Available presets:
VibrationPreset.alarmVibrationPreset.notificationVibrationPreset.heartbeatVibrationPreset.singleShortBuzzVibrationPreset.doubleBuzzVibrationPreset.tripleBuzzVibrationPreset.longAlarmBuzzVibrationPreset.pulseWaveVibrationPreset.progressiveBuzzVibrationPreset.rhythmicBuzzVibrationPreset.gentleReminderVibrationPreset.quickSuccessAlertVibrationPreset.zigZagAlertVibrationPreset.softPulseVibrationPreset.emergencyAlertVibrationPreset.heartbeatVibrationVibrationPreset.countdownTimerAlertVibrationPreset.rapidTapFeedbackVibrationPreset.dramaticNotificationVibrationPreset.urgentBuzzWave
cancel
Stop ongoing vibration.
Vibration.cancel();
Android
The VIBRATE permission is required in AndroidManifest.xml.
<uses-permission android:name="android.permission.VIBRATE"/>
Supports vibration with duration and pattern. On Android 8 (Oreo) and above, uses the VibrationEffect class. For the rest of the usage instructions, see Vibrator class documentation.
iOS
Supports vibration with duration and pattern on CoreHaptics devices. On older devices, the pattern is emulated with 500ms long vibrations.
You can check whether the current device has CoreHaptics support using hasCustomVibrationsSupport.
OpenHarmony
The OpenHarmony implementation of vibration.
vibration 在 OpenHarmony 平台的实现。
Add the following permission settings to your project's module.json5 file.
在你的项目的 module.json5 文件中增加以下权限设置。
"requestPermissions": [
{"name" : "ohos.permission.VIBRATE"},
]
Usage
dependencies:
vibration: any
vibration_ohos: any
vibrateEffect and vibrateAttribute are only exist in VibrationOhos.
(VibrationPlatform.instance as VibrationOhos).vibrate(
vibrateEffect: const VibratePreset(count: 100),
vibrateAttribute: const VibrateAttribute(
usage: 'alarm',
),
);
История изменений
3.1.8
- Fix
repeatparameter ignored on iOS. (#145 by @zeienko-vitalii)
3.1.7
- Fix Android deprecation warning for VIBRATOR_SERVICE. (#144 by @zeienko-vitalii)
3.1.7-dev.1
- Attempt to fix deprecation warning on Android.
3.1.6
- Fix crash on Android. (#140 by @armanagarwal)
3.1.5
- Adds Swift Package Manager compatibility.
3.1.4
Note: This release has breaking changes.
Plugin now requires the following:
- Android Gradle Plugin >=8.12.1
- Gradle wrapper >=8.13
- Kotlin 2.2.0
- Bump package
vibration_platform_interfaceto "0.1.1"
3.1.3
- Fix intensities on iOS.
- Lower miminum Compile SDK version for Android to 34
3.1.2
- Restore
hasAmplitudeControlandhasCustomVibrationsSupportmethods.
3.1.1
- Fix some cases where intensities were not being used correctly.
3.1.0
- Add common vibration patterns for Android and iOS.
- Add
sharpnessparameter for iOS. - Suppress deprecation warnings for
vibratemethod on Android.
3.0.0
- The plugin has been recreated from scratch to align with the latest Flutter and Dart features.
- The iOS version no longer depends on intensities and amplitude, and it now supports custom durations and patterns.
- The example app is more intuitive and user-friendly.
- Calling the
hasVibratormethod is no longer necessary. - Adjustments for null safety have been implemented.
2.1.0
- Fix vibration on iOS
- All methods are now properly null-safe
2.0.1
- Bump package
vibration_platform_interfaceto "0.0.2"
2.0.0
- Remove references to Android embedding v1
- Update package:web to ">=0.5.1 <2.0.0" (#105 by dkrutskikh)
1.9.0
- Added OpenHarmony support
- Migrate to common platform implement (vibration_platform_interface)
1.8.4
- Added Web support (#95 by san-smith)
1.8.2
- Raise minimum and target SDK versions for Android to upgrade Gradle to 7.5.
1.8.0
- Use
device_info_plusforhasAmplitudeControlandhasVibratormethods.
1.7.7
- Adds a namespace attribute to the Android build.gradle, for compatibility with Android Gradle Plugin 8.0.
1.7.6
- Update package's dart SDK max version (under 3.0.0)
1.7.5
- Bump
vibration_webto 1.6.4.
1.7.4
- Migrating to null safety.
1.7.3
- Use targetEnvironment check on iOS.
1.7.2
- Updated description to indicate web support.
1.7.1
- Fix building on iOS.
1.7.0
- Use Android Embedding v2.
1.6.1
- Added Web support (#43 by roulljdh)
1.5.0
- Fibration now works in backgroud on Android (#40 by wanghaiyang5241)
1.4.0
- Added a
hasCustomVibrationsSupportmethod (#34 by Skyost) - Use Swift 5.0
1.3.1
- Fix #32 (by Hugo Heneault)
1.3.0
- Add support for CoreHaptics on iOS devices #30 (by Leicas)
1.2.4
- Move
flutter_testto dev_dependencies. Fixes issue #24.
1.2.3
- Add proper indication of async methods to docs (by @qqgg231)
1.2.2
- Suppress deprecation warnings for
vibratemethod
1.2.1
- Maintenance release
1.2.0
- Add support for amplitude control under Android 8.0 and later (by @pmundt)
1.1.0
- Migrate to AndroidX (by @gastonmuijtjens)
- Add unit test for canceling vibration (by @vintage)
1.0.2
- Update vibration.podspec
1.0.1
- Implemented
cancelmethod for iOS
1.0.0
- Initial Release
