Method Swizzling in Dart Flutter

111 views
Skip to first unread message

Sandeep Madineni

unread,
Nov 3, 2023, 3:53:24 AM11/3/23
to Dart Misc
Is it possible to do method swizzling in Dart ? 

Basically, I would like to listen to all button clicks in entire flutter application and use it to send events for Analytics.

Is it possible to do this ? can some one shed some light on this ?

Slava Egorov

unread,
Nov 7, 2023, 3:23:54 AM11/7/23
to mi...@dartlang.org
The answer is no. There is no reliable builtin way to hook into method dispatch. 

That being said, there are various methods in Flutter to listen to all incoming tap events - the most low level one is to replace onPointerDataPacket[1] callback. Talk to somebody who knows Flutter internals - they might recommend other ways.


--
For more ways to connect visit https://dart.dev/community
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/faeaaa4a-32f5-4b4e-a544-f306d4f7d879n%40dartlang.org.

Chris Norman

unread,
Nov 7, 2023, 8:19:58 AM11/7/23
to mi...@dartlang.org
I suspect the "proper" way is to wrap each button in a custom widget which sends the analytics, but I don't know how much work that'll be.

Take care,

Chris Norman



--
Reply all
Reply to author
Forward
0 new messages