flutter_idle_detector

pub package likes popularity License: MIT

A simple and lightweight Flutter package to detect user inactivity (idle state) and trigger callbacks when the user becomes idle or active again.


✨ Features

  • Detect user inactivity (idle)
  • Trigger callback when user becomes idle
  • Detect when user becomes active again
  • Lightweight and efficient
  • Easy integration with any Flutter app

πŸš€ Why This Package?

Handling user inactivity is a common requirement in apps like:

  • πŸ” Auto logout systems
  • πŸ’€ Session timeout handling
  • πŸ“Š User activity tracking
  • πŸ”„ Auto refresh after inactivity

This package provides a simple way to detect inactivity without complex setup.


πŸ“¦ Installation

Add this to your pubspec.yaml:

dependencies:
  flutter_idle_detector: ^0.0.1

πŸ§‘β€πŸ’» Usage

Wrap your app with IdleDetector:

import 'package:flutter_idle_detector/flutter_idle_detector.dart';

IdleDetector(
  timeout: Duration(minutes: 5),
  onIdle: () {
    print("User is idle");
  },
  onActive: () {
    print("User is active again");
  },
  child: MyApp(),
);

πŸ§ͺ Example

IdleDetector(
  timeout: const Duration(seconds: 10),
  onIdle: () {
    print("πŸ”΄ User is IDLE");
  },
  onActive: () {
    print("🟒 User is ACTIVE again");
  },
  child: MaterialApp(
    home: Scaffold(
      body: Center(
        child: Text("Interact or wait 10 seconds"),
      ),
    ),
  ),
);

πŸ“Έ Demo

Add your demo GIF here (recommended)

Demo


βš™οΈ Parameters

Parameter Type Description
timeout Duration Time before user is considered idle
onIdle VoidCallback Called when user becomes idle
onActive VoidCallback Called when user becomes active again
child Widget Your app/widget tree

πŸ“± Behavior

State Supported
Foreground βœ… Yes
Background ❌ No
App Resume Detection ⚠️ Manual handling

🧠 How it works

The package listens to user interactions like taps, gestures, and pointer events. If no interaction is detected within the given timeout, the user is marked as idle.

Once interaction resumes, the onActive callback is triggered.


πŸ’‘ Best Practices

  • Use for session timeout or auto logout
  • Combine with app lifecycle for better accuracy
  • Avoid very short timeout durations in production

πŸ“‚ Example

Check the /example folder for a complete working demo.


🀝 Contributing

Contributions are welcome! Feel free to open issues or submit pull requests.


πŸ‘€ Author

AZHARKC GitHub: https://github.com/AZHARKC


πŸ“„ License

MIT License


⭐ If you like this package, please consider starring the repository!

Libraries

flutter_user_idle
A Flutter package for detecting user idle state based on pointer activity.