Calls like Posthog().screen(screenName: 'Example Screen'); should not be done in a widgets build method since the build method is potentially called multiple times. Therefore, this could lead to wrongly recorded analytics with too many screen views. Additionally, the PosthogObserver is already recording that exact screen view.
In this specific example, it might actually be acceptable, though, since it's the root widget. However, an example shouldn't be this nuanced, so it's better to remove it.
Calls like
Posthog().screen(screenName: 'Example Screen');
should not be done in a widgets build method since the build method is potentially called multiple times. Therefore, this could lead to wrongly recorded analytics with too many screen views. Additionally, thePosthogObserver
is already recording that exact screen view.In this specific example, it might actually be acceptable, though, since it's the root widget. However, an example shouldn't be this nuanced, so it's better to remove it.