wallx_setter

pub package License: MIT

A Flutter plugin to set wallpapers on Android devices. Simple, fast, and reliable way to change device wallpaper programmatically.

Features

  • ✅ Set wallpaper from local file path
  • ✅ Simple and intuitive API
  • ✅ Lightweight and fast
  • ✅ Comprehensive error handling
  • ✅ Well-documented code
  • 📱 Android support (API 16+)

Platform Support

Android iOS MacOS Web Linux Windows

Installation

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

dependencies:
  wallx_setter: ^1.0.1

Then run:

flutter pub get

Android Setup

Add the following permission to your AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-permission android:name="android.permission.SET_WALLPAPER"/>
    
    <application>
        ...
    </application>
</manifest>

Location: android/app/src/main/AndroidManifest.xml

Usage

Basic Example

import 'package:wallx_setter/wallx_setter.dart';

// Create instance
final wallxSetter = WallxSetter();

// Set wallpaper from file path
String imagePath = '/storage/emulated/0/Download/my_image.jpg';
bool? result = await wallxSetter.setWallpaper(imagePath);

if (result == true) {
  print('✓ Wallpaper set successfully!');
} else {
  print('✗ Failed to set wallpaper');
}

Complete Example with UI

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

class WallpaperScreen extends StatefulWidget {
  @override
  _WallpaperScreenState createState() => _WallpaperScreenState();
}

class _WallpaperScreenState extends State<WallpaperScreen> {
  final _wallxSetter = WallxSetter();
  bool _isLoading = false;

  Future<void> _setWallpaper() async {
    setState(() => _isLoading = true);

    try {
      // Replace with your image path
      String imagePath = '/storage/emulated/0/Download/wallpaper.jpg';
      
      bool? result = await _wallxSetter.setWallpaper(imagePath);

      if (mounted) {
        ScaffoldMessenger.of(context).showSnackBar(
          SnackBar(
            content: Text(
              result == true 
                ? 'Wallpaper set successfully!' 
                : 'Failed to set wallpaper',
            ),
            backgroundColor: result == true ? Colors.green : Colors.red,
          ),
        );
      }
    } catch (e) {
      print('Error: $e');
    } finally {
      setState(() => _isLoading = false);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Wallpaper Setter'),
      ),
      body: Center(
        child: ElevatedButton(
          onPressed: _isLoading ? null : _setWallpaper,
          child: _isLoading
              ? CircularProgressIndicator()
              : Text('Set Wallpaper'),
        ),
      ),
    );
  }
}

API Reference

WallxSetter Class

Methods

setWallpaper(String imagePath)

Sets the device wallpaper from a local file path.

Parameters:

  • imagePath (String): The absolute path to the image file

Returns:

  • Future<bool?>: Returns true if successful, false if failed, null on error

Example:

bool? result = await wallxSetter.setWallpaper('/path/to/image.jpg');

Getting Image Path

You can use packages like image_picker or file_picker to get image paths:

Using image_picker

dependencies:
  image_picker: ^1.0.1
  wallx_setter: ^1.0.1
import 'package:image_picker/image_picker.dart';
import 'package:wallx_setter/wallx_setter.dart';

Future<void> pickAndSetWallpaper() async {
  final ImagePicker picker = ImagePicker();
  final XFile? image = await picker.pickImage(source: ImageSource.gallery);
  
  if (image != null) {
    final wallxSetter = WallxSetter();
    bool? result = await wallxSetter.setWallpaper(image.path);
    
    if (result == true) {
      print('Wallpaper set!');
    }
  }
}

Using file_picker

dependencies:
  file_picker: ^6.0.0
  wallx_setter: ^1.0.1
import 'package:file_picker/file_picker.dart';
import 'package:wallx_setter/wallx_setter.dart';

Future<void> pickAndSetWallpaper() async {
  FilePickerResult? result = await FilePicker.platform.pickFiles(
    type: FileType.image,
  );
  
  if (result != null) {
    String? filePath = result.files.single.path;
    if (filePath != null) {
      final wallxSetter = WallxSetter();
      bool? success = await wallxSetter.setWallpaper(filePath);
      
      if (success == true) {
        print('Wallpaper set!');
      }
    }
  }
}

Error Handling

The plugin includes comprehensive error handling:

try {
  bool? result = await wallxSetter.setWallpaper(imagePath);
  
  if (result == true) {
    // Success
    print('Wallpaper set successfully');
  } else if (result == false) {
    // Failed - file might not exist or invalid format
    print('Failed to set wallpaper');
  } else {
    // Null - platform error occurred
    print('An error occurred');
  }
} catch (e) {
  print('Exception: $e');
}

Troubleshooting

Image not found

  • Ensure the file path is correct and absolute
  • Verify the file exists before calling setWallpaper()
  • Check file read permissions

Permission denied

  • Make sure you added SET_WALLPAPER permission to AndroidManifest.xml
  • Verify the permission is in the correct location in the manifest

Wallpaper not changing

  • Check if the image file format is supported (JPG, PNG)
  • Ensure the image file is not corrupted
  • Try with a different image file

Supported Image Formats

  • JPEG (.jpg, .jpeg)
  • PNG (.png)
  • BMP (.bmp)
  • WebP (.webp)

Requirements

  • Flutter SDK: >=3.0.0
  • Dart SDK: >=3.0.0
  • Android: API 16+ (Android 4.1+)

Examples

Check out the example directory for a complete working example.

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

Issues and Feedback

Please file issues, bugs, or feature requests in our issue tracker.

License

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

Author

AbubakrFlutter

Changelog

See CHANGELOG.md for a list of changes.


Made by AbubakrFlutter