gamepad_haptics 1.0.1 copy "gamepad_haptics: ^1.0.1" to clipboard
gamepad_haptics: ^1.0.1 copied to clipboard

PlatformiOS

A Flutter plugin to control haptic feedback on game controllers (iOS and Android). Supports 18 different vibration patterns with customizable intensity and sharpness.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:gamepad_haptics/gamepad_haptics.dart';
import 'package:gamepad_haptics_example/tabs/preset_patterns_tab.dart';
import 'package:gamepad_haptics_example/tabs/custom_pattern_builder_tab.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Gamepad Haptics Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        useMaterial3: true,
      ),
      home: const HapticsDemoPage(),
    );
  }
}

class HapticsDemoPage extends StatefulWidget {
  const HapticsDemoPage({super.key});

  @override
  State<HapticsDemoPage> createState() => _HapticsDemoPageState();
}

class _HapticsDemoPageState extends State<HapticsDemoPage> {
  bool _isControllerConnected = false;
  Timer? _connectionCheckTimer;

  @override
  void initState() {
    super.initState();
    _checkControllerConnection();
    _connectionCheckTimer = Timer.periodic(
      const Duration(seconds: 2),
      (_) => _checkControllerConnection(),
    );
  }

  @override
  void dispose() {
    _connectionCheckTimer?.cancel();
    GamepadHaptics.stopVibration();
    super.dispose();
  }

  Future<void> _checkControllerConnection() async {
    try {
      final isConnected = await GamepadHaptics.isControllerConnected();
      if (mounted) {
        setState(() {
          _isControllerConnected = isConnected;
        });
      }
    } catch (e) {
      debugPrint('Error checking controller: $e');
    }
  }

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 2,
      child: Scaffold(
        appBar: AppBar(
          title: const Text('Gamepad Haptics Demo'),
          centerTitle: true,
          elevation: 2,
          bottom: const TabBar(
            tabs: [
              Tab(icon: Icon(Icons.category), text: 'Preset Patterns'),
              Tab(icon: Icon(Icons.construction), text: 'Custom Builder'),
            ],
          ),
        ),
        body: TabBarView(
          children: [
            PresetPatternsTab(isControllerConnected: _isControllerConnected),
            CustomPatternBuilderTab(isControllerConnected: _isControllerConnected),
          ],
        ),
      ),
    );
  }
}
1
likes
145
points
110
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin to control haptic feedback on game controllers (iOS and Android). Supports 18 different vibration patterns with customizable intensity and sharpness.

Repository (GitHub)
View/report issues

Topics

#gamepad #haptics #vibration #controller #feedback

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on gamepad_haptics

Packages that implement gamepad_haptics