hit
1.2.4, released 4 months ago by zennn.dev
Decouple Flutter layout size from hit-test size to deliver taps outside parent bounds.
What it does
Separates paint and layout size from hit size in Flutter, allowing widgets to stay visually small while having a larger tap target. Delivers pointer events that fall outside a widget's layout box using a higher-level scope.
AI-written summary of version 1.2.4, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need a control to stay visually small like an icon or 1px edge but meet a comfortable touch target size.
- You need to handle taps on elements that overflow their parent bounds without breaking neighboring layouts.
Skip it when
- You have hundreds of deferred targets nested under one huge root scope, which can impact performance.
- Standard padding or sizing solutions are sufficient and do not cause layout crowding.
Strengths
- Enables precise separation of paint/layout bounds from hit-test bounds.
- Includes a built-in Dart DevTools extension for inspecting hit scopes and debugging missed taps.
- Supports slivers via SliverHitScope for custom scroll views.
Weaknesses
- Deferred hit-testing is O(n) over registered targets on a scope, meaning large numbers of targets can affect performance.
- Requires careful scope placement so that the HitScope's layout box actually covers the expanded hit area.
Setup
- Kind
- Flutter widgets
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 0
not documented
HitScope(
child: Padding(
padding: const EdgeInsets.all(12),
child: HitLayer(
alignment: Alignment.center,
behavior: HitTestBehavior.deferToChild,
hitChild: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {},
child: const SizedBox(width: 48, height: 48),
),
paintChild: const IgnorePointer(
child: Icon(Icons.add, size: 24),
),
),
),
)Alternatives
Packages that do the same job and could replace hit.
- defer_pointer
Provides a widget to render and hit‑test children outside their parent bounds.
50Compare - transparent_pointer
A widget that makes itself transparent to hit testing while letting its subtree receive pointer events.
50Compare - lazy_wrap
A Flutter widget for lazy Wrap-style layouts with fixed or variable item sizes.
72Compare - keyboard_dismisser
A Flutter widget to hide the keyboard when performing gestures outside of it.
50Compare