manage_wallpaper 0.0.1 copy "manage_wallpaper: ^0.0.1" to clipboard
manage_wallpaper: ^0.0.1 copied to clipboard

A Flutter plugin to set wallpapers and live wallpapers across multiple platforms.

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:manage_wallpaper/wallpaper.dart';

import 'package:file_picker/file_picker.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  final _wallpaperPlugin = Wallpaper();

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  Future<void> initPlatformState() async {
    String platformVersion;
    try {
      platformVersion =
          await _wallpaperPlugin.getPlatformVersion() ??
          'Unknown platform version';
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  Future<void> _pickAndSetWallpaper(BuildContext context) async {
    try {
      FilePickerResult? result = await FilePicker.platform.pickFiles(
        type: FileType.image,
      );

      if (result != null && result.files.single.path != null) {
        String path = result.files.single.path!;
        String? response = await _wallpaperPlugin.setWallpaper(path);
        if (context.mounted) {
          ScaffoldMessenger.of(
            context,
          ).showSnackBar(SnackBar(content: Text('Wallpaper set: $response')));
        }
      }
    } catch (e) {
      if (context.mounted) {
        ScaffoldMessenger.of(
          context,
        ).showSnackBar(SnackBar(content: Text('Error: $e')));
      }
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Builder(
        builder: (context) => Scaffold(
          appBar: AppBar(title: const Text('Wallpaper Plugin Example')),
          body: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text('Running on: $_platformVersion\n'),
                const SizedBox(height: 20),
                ElevatedButton(
                  onPressed: () => _pickAndSetWallpaper(context),
                  child: const Text('Pick Image and Set Wallpaper'),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
2
likes
150
points
99
downloads

Documentation

API reference

Publisher

verified publisherdb-rm.dev

Weekly Downloads

A Flutter plugin to set wallpapers and live wallpapers across multiple platforms.

Homepage
Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on manage_wallpaper

Packages that implement manage_wallpaper