0 purchases
win gamepad
win_gamepad #
A Flutter plugin for Windows for receiving input from game controllers which support XInput. This plugin uses XInput Game Controller API for receiving input from game controllers.
Installation #
To use this plugin, add win_gamepad as a dependency in your pubspec.yaml file.
Usage #
Import it
import 'package:win_gamepad/gamepad.dart';
copied to clipboard
Initialize gamepad
// default id = 0
// default auto vibration = false
Gamepad gamepad = Gamepad();
@override
void initState() {
super.initState();
// initialize gamepad and selects first available device or 0
gamepad.initialize(onCallback: (gamepadState) {
print(gamepadState);
setState(() {});
});
}
copied to clipboard
Get available gamepad ids
// returns avaible device ids
gamepad.getAvaibleDevices();
copied to clipboard
Select gamepad
gamepad.selectGamepad(id);
copied to clipboard
Activate auto vibration
// when auto vibration is true, gamepad vibrates via triggers.
gamepad.setAutoVibration(true);
copied to clipboard
Vibrate gamepad
// leftMotorSpeed and rightMotorSpeed are should be between 0.0 and 1.0
gamepad.setVibration(leftMotorSpeed, rightMotorSpeed);
copied to clipboard
For testing there is a gamepad layout
import 'package:win_gamepad/gamepad_layout.dart';
...
GamepadLayout(gamepad: gamepad,)
...
copied to clipboard
Example #
import 'package:flutter/material.dart';
import 'package:win_gamepad/gamepad.dart';
import 'package:win_gamepad/gamepad_layout.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
Gamepad gamepad = Gamepad();
@override
void initState() {
super.initState();
gamepad.initialize(onCallback: (gamepadState) {
setState(() {});
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin win_gamepad'),
),
body: Center(
child: Column(
children: [
Opacity(
opacity: 1,
child: GamepadLayout(
gamepad: gamepad,
),
),
],
),
),
),
);
}
}
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.