rmtmckenzie / flutter_native_device_orientation

Native device orientation plugin for flutter.
MIT License
76 stars 63 forks source link

NativeDeviceOrientation 1.1.4 uses unchecked or unsafe operations #56

Closed manudicri closed 9 months ago

manudicri commented 1 year ago

When building the apk of my app, this warning appears in the console.

Note: /Users/manudicri/.pub-cache/hosted/pub.dev/native_device_orientation-1.1.4/android/src/main/java/com/github/rmtmckenzie/native_device_orientation/NativeDeviceOrientationPlugin.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details.

That's basically it.

My flutter doctor -v:

[✓] Flutter (Channel stable, 3.7.7, on macOS 13.4 22F66 darwin-arm64, locale it-IT)
    • Flutter version 3.7.7 on channel stable at /Users/manudicri/Development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2ad6cd72c0 (6 months ago), 2023-03-08 09:41:59 -0800
    • Engine revision 1837b5be5f
    • Dart version 2.19.4
    • DevTools version 2.20.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /Users/manudicri/Library/Android/sdk
    • Platform android-33, build-tools 33.0.1
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E222b
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)

[✓] VS Code (version 1.81.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.54.0

[✓] Connected device (3 available)
    • iPhone 14 Pro (mobile) • 688E3477-BEF0-451B-836F-806FC8B9351D • ios            •
      com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator)
    • macOS (desktop)        • macos                                • darwin-arm64   • macOS 13.4 22F66 darwin-arm64
    • Chrome (web)           • chrome                               • web-javascript • Google Chrome 116.0.5845.179

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
Thowk commented 9 months ago

I get the same warning.

It seems like this cast is the cause:

https://github.com/rmtmckenzie/flutter_native_device_orientation/blob/85b3227f7a1fbfd49baaa4323890e2c0e0efb725/android/src/main/java/com/github/rmtmckenzie/native_device_orientation/NativeDeviceOrientationPlugin.java#L100-L103

To fix this, I've found that after creating a custom type (without using a generic), the compiler passes the test (https://stackoverflow.com/a/49832115) :

// your class extends generic but is not generic
class EventParameters extends Map<String, Object> { }

// then change your cast like this: 
EventParameters params = (EventParameters) parameters; // here we have NO warning for unchecked cast

@rmtmckenzie What do you think about it? It might be worth updating, one warning less :)

rmtmckenzie commented 9 months ago

Should be fixed in the newest release.