win_gamepad 0.1.0
win_gamepad: ^0.1.0 copied to clipboard

A Flutter plugin for Windows for receiving input from game controllers which support XInput.

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';

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(() {});
    });
}

Get available gamepad ids

// returns avaible device ids
gamepad.getAvaibleDevices();

Select gamepad

gamepad.selectGamepad(id);

Activate auto vibration

// when auto vibration is true, gamepad vibrates via triggers.
gamepad.setAutoVibration(true);

Vibrate gamepad

// leftMotorSpeed and rightMotorSpeed are should be between 0.0 and 1.0
gamepad.setVibration(leftMotorSpeed, rightMotorSpeed);

For testing there is a gamepad layout

import 'package:win_gamepad/gamepad_layout.dart';
...

    GamepadLayout(gamepad: gamepad,)

...

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,
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
0
likes
100
pub points
28%
popularity

A Flutter plugin for Windows for receiving input from game controllers which support XInput.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

flutter

More

Packages that depend on win_gamepad