Skip to content
pubscout

anchor

0.0.7, released a year ago by degenk.com

Calculates optimal overlay position relative to an anchor using a middleware pipeline

WASM-ready
$ flutter pub add anchor
Source repository

What it does

Anchor provides a pure Dart engine to compute the best position for floating elements like tooltips or popovers. It uses a series of middleware to adjust offset, flip, shift, auto‑placement, size, and virtual references.

AI-written summary of version 0.0.7, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need fine‑grained control over overlay placement
  • You want to support tooltips, popovers, dropdowns, or custom overlays
  • You prefer a pure calculation engine without UI widgets

Skip it when

  • You need a ready‑made widget that handles positioning and rendering
  • You are building a simple UI that can use Flutter’s built‑in positioning

Strengths

  • Extensible middleware architecture
  • Inspired by Floating UI for familiar patterns
  • Pure Dart, no platform dependencies
  • Supports virtual references and size calculations

Weaknesses

  • No UI widget, only calculation logic
  • Requires manual integration into UI code
  • Limited to positioning, not rendering

Setup

Kind
Flutter widgets
Effort
Low
Code generation
No
Direct dependencies
1
import 'package:anchor/position.dart';
import 'package:anchor/middlewares/flip.dart';
import 'package:anchor/middlewares/offset.dart';
import 'package:anchor/middlewares/shift.dart';

final config = PositioningConfig(
  childPosition: const Offset(100, 100),
  childSize: const Size(50, 50),
  viewportSize: const Size(800, 600),
  overlayWidth: 150,
  overlayHeight: 75,
  placement: Placement.top,
);

final pipeline = PositioningPipeline(
  middlewares: [
    const OffsetMiddleware(mainAxis: 10),
    const FlipMiddleware(),
    const ShiftMiddleware(),
  ],
);

final result = pipeline.run(config: config);
print(result.state.anchorPoints.offset);

Works with

Packages commonly used together with anchor: ones it builds on, ones built on it, and its own family.