๐Ÿ”‹ Wakelock Fixed

Pub version GitHub stars License: MIT Flutter

๐Ÿš€ Enhanced & Fixed Version of the popular wakelock plugin for Flutter

A robust, cross-platform Flutter plugin that prevents your device screen from sleeping. Perfect for apps that need to keep the display active during presentations, videos, games, or any interactive content.


โœจ Features

  • ๐ŸŽฏ Zero Permissions Required - Works out of the box on all platforms
  • ๐ŸŒ Cross-Platform Support - Android, iOS, Web, macOS, Windows
  • ๐Ÿ”ง Simple API - Just a few lines of code to get started
  • ๐Ÿ›ก๏ธ Reliable - Fixed version with improved stability
  • โšก Lightweight - Minimal overhead and dependencies
  • ๐ŸŽจ Modern Design - Clean, intuitive interface

๐Ÿ“ฑ Supported Platforms

Platform Status Notes
๐Ÿค– Android โœ… Fully Supported API 16+
๐ŸŽ iOS โœ… Fully Supported iOS 9.0+
๐ŸŒ Web โœ… Fully Supported All modern browsers
๐Ÿ–ฅ๏ธ macOS โœ… Fully Supported macOS 10.11+
๐ŸชŸ Windows โœ… Fully Supported Windows 10+
๐Ÿง Linux ๐Ÿšง Coming Soon Planned for future release

๐Ÿš€ Quick Start

1. Add Dependency

Add this to your package's pubspec.yaml file:

dependencies:
  wakelock_fixed: ^0.6.2

2. Import & Use

import 'package:wakelock_fixed/wakelock_fixed.dart';

// Keep screen awake
Wakelock.enable();

// Let screen sleep again
Wakelock.disable();

// Check current status
bool isActive = await Wakelock.enabled;

๐Ÿ’ก Usage Examples

Basic Usage

import 'package:flutter/material.dart';
import 'package:wakelock_fixed/wakelock_fixed.dart';

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  bool _isWakelockEnabled = false;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Wakelock Demo'),
          backgroundColor: Colors.deepPurple,
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Icon(
                _isWakelockEnabled ? Icons.battery_charging_full : Icons.battery_std,
                size: 64,
                color: _isWakelockEnabled ? Colors.green : Colors.grey,
              ),
              SizedBox(height: 20),
              Text(
                _isWakelockEnabled ? 'Screen is awake!' : 'Screen can sleep',
                style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
              ),
              SizedBox(height: 30),
              ElevatedButton.icon(
                onPressed: () async {
                  if (_isWakelockEnabled) {
                    await Wakelock.disable();
                  } else {
                    await Wakelock.enable();
                  }
                  setState(() {
                    _isWakelockEnabled = await Wakelock.enabled;
                  });
                },
                icon: Icon(_isWakelockEnabled ? Icons.pause : Icons.play_arrow),
                label: Text(_isWakelockEnabled ? 'Disable Wakelock' : 'Enable Wakelock'),
                style: ElevatedButton.styleFrom(
                  backgroundColor: _isWakelockEnabled ? Colors.red : Colors.green,
                  foregroundColor: Colors.white,
                  padding: EdgeInsets.symmetric(horizontal: 24, vertical: 12),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Advanced Usage

// Toggle wakelock with a boolean
await Wakelock.toggle(enable: true);

// Check if wakelock is currently active
bool isActive = await Wakelock.enabled;

// Enable wakelock and wait for completion
await Wakelock.enable();
print('Wakelock is now active!');

// Disable wakelock
await Wakelock.disable();
print('Wakelock has been disabled!');

Proper Initialization

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  
  // Enable wakelock if needed
  await Wakelock.enable();
  
  runApp(MyApp());
}

๐ŸŽฏ Best Practices

โœ… Do's

  • Enable wakelock only when needed (e.g., during video playback)
  • Disable wakelock when not needed to save battery
  • Check wakelock status before enabling/disabling
  • Use in specific widgets rather than globally

โŒ Don'ts

  • Don't enable wakelock globally in main()
  • Don't forget to disable wakelock when done
  • Don't ignore battery impact on user devices

๐Ÿ”ง API Reference

Methods

Method Description Returns
Wakelock.enable() Enables the screen wakelock Future<void>
Wakelock.disable() Disables the screen wakelock Future<void>
Wakelock.toggle(enable: bool) Toggles wakelock on/off Future<void>

Properties

Property Description Type
Wakelock.enabled Current wakelock status Future<bool>

๐Ÿ†š What's Fixed?

This is an enhanced version of the original wakelock plugin with the following improvements:

  • ๐Ÿ”ง Fixed Android build issues
  • ๐Ÿ›ก๏ธ Improved error handling
  • โšก Better performance
  • ๐ŸŽฏ Enhanced reliability
  • ๐Ÿ“ฑ Updated dependencies
  • ๐Ÿงช Better testing coverage

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

๐Ÿ“ž Support

If you encounter any issues or have questions:


โญ Star this repository if you found it helpful!

Made with โค๏ธ by boughdiri-dorsaf

Libraries

wakelock_fixed