benjamindean / flutter_vibration

Handle vibration on iOS and Android in Flutter apps
229 stars 69 forks source link

hasVibrator() throws exceptions on MacOS #83

Open fotiDim opened 1 year ago

fotiDim commented 1 year ago

I'd live to avoid surrounding the calls to this package with try catch when running on Mac. Currently hasVibrator() throws unimplemented method exception. It would be great if it just returned false. Same would probably apply for the rest of the unsupported platforms.

benjamindean commented 1 year ago

Can you provide the full error message, please?

cbenhagen commented 1 year ago

@benjamindean the error would look like this:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method hasVibrator on channel vibration)
#0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:308:7)

It would be great if not supported platforms would at least return false on hasVibrator().

benjamindean commented 1 year ago

@fotiDim @cbenhagen Published version 1.8.0. You can try again. It uses device_info_plus for handling that case.

cbenhagen commented 1 year ago

@benjamindean thanks for the quick response! Introducing this new dependency is not needed to solve this specific issue and causes new issues in my project. Why not just try / expept in the platform interface and return false if there is no method channel? The new Android code seems worse than before. Not every physical Android device has a vibrator. A tablet or a TV most likely do not have one. The same goes for iOS. Do iPads really have a vibrator?

Also I am not sure if checking if this is a physical device should be part of the plugin or not. For what I care, if the emulated vibrator is behaveing like a real one, I am happy to get true as a return value for hasVibrator(). After all the same is true for any other hardware that is emulated.

benjamindean commented 1 year ago

@cbenhagen Yes, I'm aware of these problems. However, there has been quite a few issues reported about that, so I decided to stay on a safe side and implement a non-platform approach. Well, sort of. You won't need the vibration on a non-physical device anyway. Honestly, I would just drop the hasVibrator check altogether and make it return nothing if vibration is triggered on a non-supported device.