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

A Flutter plugin for switching your app launcher icons.

example/lib/main.dart

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

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

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

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

enum AppIcons {
  whiteBlue('WhiteBlue'),
  whitePink('WhitePink'),
  blackBlue('BlackBlue'),
  blackPink('BlackPink');

  final String name;

  const AppIcons(this.name);
}

class _MyAppState extends State<MyApp> {
  final _launcherIconSwitcherPlugin = LauncherIconSwitcher();
  bool isInitialized = false;
  String? currentIcon;

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

  Future initPlugin() async {
    await _launcherIconSwitcherPlugin.initialize(AppIcons.values.map((e) => e.name).toList(), AppIcons.whiteBlue.name);
    currentIcon = await _launcherIconSwitcherPlugin.getCurrentIcon();
    setState(() => isInitialized = true);
  }

  Future changeIcon(AppIcons icon) async {
    await _launcherIconSwitcherPlugin.setIcon(icon.name);
    setState(() => currentIcon = icon.name);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: isInitialized
              ? Wrap(
                  spacing: 50,
                  runSpacing: 50,
                  alignment: WrapAlignment.center,
                  children: AppIcons.values
                      .map((e) => GestureDetector(
                            onTap: () => changeIcon(e),
                            child: Container(
                              width: 100,
                              height: 100,
                              decoration: BoxDecoration(
                                  borderRadius: BorderRadius.circular(15),
                                  border: Border.all(
                                      color: currentIcon == e.name ? Colors.green : Colors.black45, width: 2),
                                  image: DecorationImage(
                                      image: AssetImage(
                                          'assets/sharp-${e.name.replaceAllMapped(RegExp(r'[A-Z]'), (match) => ' ${match.group(0)!.toLowerCase()}').trim().split(' ').join('-')}.png'))),
                            ),
                          ))
                      .toList(),
                )
              : const CircularProgressIndicator(),
        ),
      ),
    );
  }
}
18
likes
140
points
295
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin for switching your app launcher icons.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on launcher_icon_switcher