Skip to main content

pickpick 0.1.0 copy "pickpick: ^0.1.0" to clipboard
pickpick: ^0.1.0 copied to clipboard

Pick an opaque sRGB color anywhere on screen with native pickers on macOS, Linux, Windows, and supported web browsers.

example/lib/main.dart

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

/// Runs a small manual selection and cancellation demo.
void main() => runApp(const MaterialApp(home: PickerExample()));

/// Shows the last selected color and any platform error.
class PickerExample extends StatefulWidget {
  /// Creates the example screen.
  const PickerExample({super.key});

  @override
  State<PickerExample> createState() => _PickerExampleState();
}

/// Keeps the previous color intact when the user cancels.
class _PickerExampleState extends State<PickerExample> {
  /// Client shared by all button presses.
  static const Pickpick _picker = Pickpick();

  /// Current opaque sRGB value.
  int _color = 0xff007cf9;

  /// Whether a system request is pending.
  bool _picking = false;

  /// Last request's feedback.
  String? _message;

  /// Starts directly in the gesture callback to preserve browser activation.
  Future<void> _pick() async {
    setState(() {
      _picking = true;
      _message = null;
    });
    try {
      final int? color = await _picker.pick();
      if (!mounted) {
        return;
      }
      setState(() {
        if (color != null) {
          _color = color;
        }
        _message = color == null ? 'Cancelled — previous color kept.' : 'Color selected.';
      });
    } on Object catch (error) {
      if (mounted) {
        setState(() => _message = 'Selection failed: $error');
      }
    } finally {
      if (mounted) {
        setState(() => _picking = false);
      }
    }
  }

  @override
  Widget build(BuildContext context) => Scaffold(
    appBar: AppBar(title: const Text('Pickpick')),
    body: Center(
      child: Padding(
        padding: const .all(24),
        child: Column(
          mainAxisSize: .min,
          spacing: 24,
          children: [
            SizedBox(width: 160, height: 160, child: ColoredBox(color: Color(_color))),
            Text('#${(_color & 0xffffff).toRadixString(16).padLeft(6, '0').toUpperCase()}'),
            FilledButton(
              onPressed: _picker.available && !_picking ? _pick : null,
              child: Text(_picking ? 'Choose a pixel or press Escape…' : 'Pick a screen color'),
            ),
            if (!_picker.available) const Text('No system picker is available on this platform.'),
            if (_message case final String message) Text(message),
          ],
        ),
      ),
    ),
  );
}
0
likes
150
points
37
downloads
screenshot

Documentation

API reference

Publisher

verified publisherfocale-editor.app

Weekly Downloads

Pick an opaque sRGB color anywhere on screen with native pickers on macOS, Linux, Windows, and supported web browsers.

Repository (GitHub)
View/report issues
Contributing

Topics

#color #eyedropper #desktop #flutter-plugin #web

License

MIT (license)

Dependencies

dbus, flutter, flutter_web_plugins, plugin_platform_interface, uuid, web

More

Packages that depend on pickpick

Packages that implement pickpick