[Feature] Add multi-platform safety#20
Conversation
…b, macOS, Windows, Linux, and other desktop/mobile targets)
istornz
left a comment
There was a problem hiding this comment.
Thanks for you PR, I let some little comments 👍
| class Gaimon { | ||
| static const MethodChannel _channel = MethodChannel('gaimon'); | ||
|
|
||
| static bool get _isAndroid => !kIsWeb && Platform.isAndroid; |
There was a problem hiding this comment.
I think this is enough, same for iOS
| static bool get _isAndroid => !kIsWeb && Platform.isAndroid; | |
| static bool get _isAndroid => Platform.isAndroid; |
There was a problem hiding this comment.
Sorry @istornz I'm not sure I'm following - web doesn't support the Platform API - so why wouldn't we add this before a native platform check?
|
|
||
| static bool get _isAndroid => !kIsWeb && Platform.isAndroid; | ||
| static bool get _isIOS => !kIsWeb && Platform.isIOS; | ||
| static bool get _supportsMethodChannel => _isAndroid || _isIOS; |
There was a problem hiding this comment.
Maybe adding the kIsWeb in this condition is better?
There was a problem hiding this comment.
@istornz This package only supports Android and iOS, so I'm not sure why adding a kIsWeb would be useful here.
There was a problem hiding this comment.
@istornz I don't think we need a specific kIsWeb check since any platform other than Android and iOS will safely fail using _supportsMethodChannel.
We still want to add the kIsWeb check before the Platform checks in case.
For context: the app I'm developing is available on Android, iOS, MacOS, and Web, so I needed this to fail gracefully on MacOS and Web, but still work on Android and iOS.
Description
Addresses: #19
This PR resolves issues when using the
gaimonpackage in multi-platform Flutter applications (e.g. Web, macOS, Windows, Linux).Previously, the package would:
Solution
kIsWebguards to safely short-circuitPlatformchecks on the Web.MethodChannelinvocations (_channel.invokeMethod) to ensure they are only triggered on supported mobile platforms (Android and iOS).try-catchsafety tocanSupportsHapticto fallback tofalsein case of unexpected platform errors.HapticFeedback.selectionClick(),HapticFeedback.heavyImpact()) to run untouched as they are natively stubbed/handled safely on all platforms by Flutter.Documentation
Documented platform compatibility and fallback behavior in
README.md