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