desktop_wallpaper_set 0.0.2 copy "desktop_wallpaper_set: ^0.0.2" to clipboard
desktop_wallpaper_set: ^0.0.2 copied to clipboard

PlatformmacOS
outdated

Flutter plugin for setting desktop wallpaper. Supports macos.

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:desktop_wallpaper_set/desktop_wallpaper_set.dart';
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:desktop_wallpaper_set/type.dart';

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

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

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

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  String _setImgBtnText = 'set picture wallpaper ';
  String _setVideoBtnText = 'set video wallpaper';

  final _desktopWallpaperSetPlugin = DesktopWallpaperSet();

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      platformVersion = await _desktopWallpaperSetPlugin.getPlatformVersion() ??
          'Unknown platform version';
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

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

  Future<void> onSetImgWallpaper() async {
    String setBtnText;
    final file = await DefaultCacheManager().getSingleFile(
        "http://i0.hdslb.com/bfs/baselabs/d8e091a5be327e2a24fa62f794281448a2010f7f.png");
    setBtnText = await _desktopWallpaperSetPlugin.setWallpaper(
            file.path, WallpaperType.img) ??
        'error';
    setState(() {
      _setImgBtnText = setBtnText;
    });
  }

  Future<void> onSetVideoWallpaper() async {
    String setBtnText;
    final file = await DefaultCacheManager().getSingleFile(
        "https://activity.hdslb.com/blackboard/static/20220829/a370089fc7c797ab7a9d638df8c9cbf7/PaGtZVhRco.mp4");
    setBtnText = await _desktopWallpaperSetPlugin.setWallpaper(
            file.path, WallpaperType.video) ??
        'error';
    setState(() {
      _setVideoBtnText = setBtnText;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Walllpapler Set Plugin'),
        ),
        body: Center(
          child: Column(
            children: [
              Text('Running on: $_platformVersion\n'),
              ElevatedButton(
                  onPressed: onSetImgWallpaper, child: Text(_setImgBtnText)),
              const SizedBox(
                height: 20,
              ),
              ElevatedButton(
                  onPressed: onSetVideoWallpaper, child: Text(_setVideoBtnText))
            ],
          ),
        ),
      ),
    );
  }
}
8
likes
150
pub points
0%
popularity

Publisher

unverified uploader

Flutter plugin for setting desktop wallpaper. Supports macos.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on desktop_wallpaper_set