mixpanel-flutter icon indicating copy to clipboard operation
mixpanel-flutter copied to clipboard

Implement setLoggingEnabled for Flutter Web

Open Copilot opened this issue 7 months ago • 3 comments

Summary

This PR implements setLoggingEnabled support for Flutter Web platform, which was previously throwing an "Unimplemented" error. The implementation follows the existing pattern used by setServerURL and uses the JavaScript library's set_config method with the debug parameter.

Changes Made

1. Added Web Platform Support

  • Added setLoggingEnabled case to the method handler switch statement in lib/mixpanel_flutter_web.dart
  • Implemented handleSetLoggingEnabled method that calls set_config({'debug': loggingEnabled})

2. Implementation Details

void handleSetLoggingEnabled(MethodCall call) {
  Map<Object?, Object?> args = call.arguments as Map<Object?, Object?>;
  bool loggingEnabled = args['loggingEnabled'] as bool;
  set_config(safeJsify({'debug': loggingEnabled}));
}

3. Test Coverage

  • Added test case to verify method argument structure
  • All 69 tests passing (including existing tests)

Technical Approach

The implementation follows the exact same pattern as the existing setServerURL method:

  • Extracts the boolean parameter from method call arguments
  • Uses set_config JavaScript binding with appropriate parameter
  • Applies safeJsify for proper JavaScript interop

Before:

mixpanel.setLoggingEnabled(true);  // Throws PlatformException on Web

After:

mixpanel.setLoggingEnabled(true);   // Works on Web, iOS, and Android
// Calls: mixpanel.set_config({debug: true}) in JavaScript

Verification

  • ✅ All existing tests continue to pass
  • ✅ New test validates proper argument handling
  • ✅ No breaking changes to existing functionality
  • ✅ Follows established code patterns and style
  • ✅ Minimal implementation (8 lines of code)

Fixes #201.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot avatar Jul 07 '25 23:07 Copilot