Skip to content

feat: add posthog_dart package and restructure to multi-package monorepo#313

Draft
marandaneto wants to merge 20 commits intomainfrom
feat/posthog-dart
Draft

feat: add posthog_dart package and restructure to multi-package monorepo#313
marandaneto wants to merge 20 commits intomainfrom
feat/posthog-dart

Conversation

@marandaneto
Copy link
Member

@marandaneto marandaneto commented Feb 28, 2026

💡 Motivation and Context

Adds the posthog_dart pure Dart SDK as a new package within this workspace, enabling PostHog support on Linux and Windows platforms via Flutter.

What this PR does:

depends on #312

  • Dart-based platform implementation: New PosthogFlutterDart class that wraps posthog_dart for Linux/Windows, registered as a dartPluginClass in pubspec.yaml
  • Shared types: Moved PostHogFeatureFlagResult to posthog_dart as the single source of truth, re-exported from posthog_flutter
  • Renamed FeatureFlagResultPostHogFeatureFlagResult and FeatureFlagResultOptionsPostHogFeatureFlagResultOptions** for consistent naming
  • Restructured examples: example/examples/flutter_example/ + examples/dart_example/
  • Multi-package release process: Updated changesets, CI, publish workflows, bump-version script, and RELEASING.md to handle independent versioning and publishing of both packages

New platform support:

  • Linux and Windows now use posthog_dart SDK directly (no native method channels)
  • All existing platforms (iOS, Android, macOS, Web) continue to use native implementations unchanged

💚 How did you test it?

  • All 93 posthog_flutter tests pass
  • All 35 posthog_dart tests pass
  • dart analyze clean (only pre-existing example app infos and expected path dependency warning)
  • flutter pub get resolves successfully across the full workspace

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran pnpm changeset to generate a changeset file
  • Added the release label to the PR

- Move posthog-dart SDK into workspace as posthog_dart package
- Add Dart-based platform implementation for Linux/Windows (PosthogFlutterDart)
- Move PostHogFeatureFlagResult to posthog_dart as shared type
- Restructure examples: example/ → examples/flutter_example/ + examples/dart_example/
- Adapt release process, CI, and changeset config for multi-package
@marandaneto marandaneto requested a review from a team as a code owner February 28, 2026 13:18
@marandaneto marandaneto changed the base branch from main to refactor/pub-workspace February 28, 2026 13:19
posthog_dart doesn't use any features beyond Dart 3.6 (sealed classes
are from Dart 3.0). The ^3.11.0 constraint was just whatever the
original author had installed.
All platforms are supported: iOS/Android/macOS via method channels,
web via JS interop, Linux/Windows via posthog_dart. The function
was always returning true, making every check dead code.

Replaced the two web-specific guards in error tracking with kIsWeb.
@marandaneto marandaneto marked this pull request as draft February 28, 2026 13:35
…ndows example support

- Run dart format on all posthog_dart files
- Fix dartPluginClass registration: export PosthogFlutterDart from main
  library with conditional import (stub on web, real on dart:io platforms)
- Add Linux and Windows desktop support to flutter example app
- Remove isSupportedPlatform checks (already done) cleanup
The path dependency on posthog_dart is expected during development
and is converted to a versioned dependency before publishing by
the bump-version script.
The Dart workspace resolution automatically resolves posthog_dart: ^0.1.0
to the local workspace copy. This removes the invalid_dependency warning
and the bump-version.sh hack to convert path→version before publishing.
…share PostHogPersonProfiles

- posthog_dart: PostHogCoreOptions → PostHogConfig, PersonProfiles → PostHogPersonProfiles
- posthog_flutter: class renamed to PostHogFlutterConfig with typedef PostHogConfig = PostHogFlutterConfig for backwards compat
- PostHogPersonProfiles re-exported from posthog_dart (single source of truth)
- PostHogFlutterConfig.toCoreConfig() converts Flutter config to core config
- Removed _mapPersonProfiles() mapping function from dart platform impl
- Replace disabled/defaultOptIn with optOut in PostHogConfig (dart)
- Add debug field to PostHogConfig (dart) - auto-enables debug logging
- PostHogFlutterConfig.toCoreConfig() now maps optOut and debug directly
- Update examples and tests for new field names
- Move BeforeSendCallback (FutureOr-based) and PostHogEvent to posthog_dart
- Remove CaptureEvent and BeforeSendFn from posthog_dart (replaced by unified types)
- Remove duplicate PostHogEvent class from posthog_flutter (re-export from dart)
- PostHogEvent now has: uuid, event, properties, userProperties,
  userPropertiesSetOnce, timestamp (superset of both old types)
- posthog_dart beforeSend now supports async callbacks (FutureOr)
- Sync callbacks still execute synchronously (no unnecessary Future wrapping)
- posthog_flutter re-exports BeforeSendCallback and PostHogEvent from posthog_dart
…vent

PostHogConfig changes:
- flushInterval: int (ms) → Duration (default: 10s)
- requestTimeout: int (ms) → Duration (default: 10s)
- featureFlagsRequestTimeoutMs: int? → featureFlagsRequestTimeout: Duration?
- remoteConfigRequestTimeoutMs: int → remoteConfigRequestTimeout: Duration (default: 3s)
- sessionExpirationTimeSeconds: int → sessionExpiration: Duration (default: 30min)
- fetchRetryDelay: int (ms) → Duration (default: 3s)
- sendFeatureFlagEvent → sendFeatureFlagEvents (matches Flutter naming)
- shutdown(timeoutMs:) → shutdown(timeout:) Duration param

Internal changes:
- All internal int ms fields converted to Duration
- retriable() retryDelay changed from int to Duration
- Timer/timeout calls use Duration directly instead of wrapping ints
- featureFlagsRequestTimeout: Duration? → Duration (default: 10s)
- disableGeoip: bool? → bool (default: false)
- Remove withDefaults() from PostHogConfig (no longer needed)
- Remove ?? fallbacks in PostHogCore and PostHogCoreStateless
- flushInterval: 10s → 30s (match Flutter)
- maxBatchSize: 100 → 50 (match Flutter)
uuid is now a non-nullable String that auto-generates a UUIDv7 if
not explicitly provided. Callers no longer need to handle null uuids.
…stHogEvent properties

Non-nullable values are the correct contract — property values should
always be non-null. Also removed now-redundant .cast<String, Object>()
calls in Flutter platform implementations.
- Copy LICENSE to posthog_dart/ and posthog_flutter/
- Copy README.md to posthog_flutter/
- Add .pubignore to both packages to exclude test/, package.json, etc.
- Both packages now pass pub publish --dry-run
Base automatically changed from refactor/pub-workspace to main March 2, 2026 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant