-
-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Support for Web #48
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution! I will be super cool to have support on web too, I have left some comments, let me know of anything
packages/gamepads_web/pubspec.yaml
Outdated
flutter_web_plugins: | ||
sdk: flutter | ||
gamepads_platform_interface: ^0.1.2+1 | ||
js: ^0.6.3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that the dart:js
package is deprecated: https://dart.dev/interop/js-interop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for reminding! I have updated to use js_interop and package:web instead of package:js and dart:html.
final gamepads = navigator.getGamepads(); | ||
return List.generate(gamepads.length, (i) { | ||
final gamepad = gamepads[i]; | ||
if (gamepad != null) { | ||
return gamepad; | ||
} | ||
return null; | ||
}).where((gamepad) => gamepad != null).toList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final gamepads = navigator.getGamepads(); | |
return List.generate(gamepads.length, (i) { | |
final gamepad = gamepads[i]; | |
if (gamepad != null) { | |
return gamepad; | |
} | |
return null; | |
}).where((gamepad) => gamepad != null).toList(); | |
return navigator.getGamepads().toDart.whereNotNull(); |
Shouldn't this be enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did't notice that I can use gamepad in package:web. Updated the implementation.
return controllers; | ||
} | ||
|
||
List<dynamic> getGamepadList() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't the list be typed here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did't get it well. Does the latest implementation look fine?
cc100bd
to
f738725
Compare
@spydon @erickzanardo Any more suggestions? |
import 'package:gamepads_platform_interface/gamepads_platform_interface.dart'; | ||
import 'package:web/web.dart'; | ||
|
||
List<GamepadController> getGamepads(GamepadsPlatformInterface plugin) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file should live in src
right? And not be exposed directly to the user, since it's not part of the interface.
} | ||
} | ||
|
||
/// Constructs a GamepadsWeb |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Constructs a GamepadsWeb |
The dart docs should talk about what it does, docs like "constructor constructs" doesn't give anything, so I think you can just remove this.
Also this:
So the SDK has to be bumped to 3.4 everywhere, and then you can use web ^1.1.0 (And flutter has to be bumped accordingly). |
Popping in to mention that there is a Github issue in this project associated with web support. I made a proof of concept for a web implementation earlier this year and I wouldn't consider web to be a stable platform for the purposes of this package, see comments on the issue. |
I am developing an app requiring web support for gamepads. I would like to contribute to this project. Please help review this pull request. Thanks!