Skip to content

Instantly share code, notes, and snippets.

@ltOgt
Created August 24, 2022 09:49
Show Gist options
  • Save ltOgt/084257d7707cfc629844b2b72e9d6ba4 to your computer and use it in GitHub Desktop.
Save ltOgt/084257d7707cfc629844b2b72e9d6ba4 to your computer and use it in GitHub Desktop.
class MyMetaData {
// Whatever you want
}
// In the hit test target, e.g. drag target
return MyParentTree(
child: MetaData(
metaData: MyMetaData(...),
child: MyChildTree(),
),
);
// In the callback where you hit test; e.g. in the drag update
final hitTestRect = getHitTestRectFromSomewhere();
final HitTestResult r = HitTestResult();
WidgetsBinding.instance?.hitTest(r, hitTestRect);
for (final HitTestEntry hte in r.path) {
final target = hte.target;
if (target is RenderMetaData) {
final metaData = target.metaData;
if (metaData is MyMetaData) {
// Do stuff with the found MyMetaData
// E.g. trigger the drop to the target
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment