wakelock_fixed 0.6.3
wakelock_fixed: ^0.6.3 copied to clipboard
Fixed version of wakelock plugin that allows you to keep the device screen awake, i.e. prevent the screen from sleeping on Android, iOS, macOS, Windows, and web.
๐ Wakelock Fixed #
๐ 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.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
๐ License #
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments #
- Original wakelock plugin by creativecreatorormaybenot
- Flutter team for the amazing framework
- All contributors and users
๐ Support #
If you encounter any issues or have questions:
- ๐ง Issues: GitHub Issues
- ๐ฌ Discussions: GitHub Discussions
- ๐ Documentation: Pub.dev
โญ Star this repository if you found it helpful!
Made with โค๏ธ by boughdiri-dorsaf