mixpanel-flutter
mixpanel-flutter copied to clipboard
Implement setLoggingEnabled for Flutter Web
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
setLoggingEnabledcase to the method handler switch statement inlib/mixpanel_flutter_web.dart - Implemented
handleSetLoggingEnabledmethod that callsset_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_configJavaScript binding with appropriate parameter - Applies
safeJsifyfor 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.