Skip to content

refactor: Hides configuration from public interface and make isBuilt final #233

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gabrielgarciagava
Copy link
Contributor

@gabrielgarciagava gabrielgarciagava commented Mar 5, 2025

TL;DR This PR achieves what is described in this link: https://amplitude.com/docs/sdks/analytics/flutter/flutter-sdk-4-0-migration-guide#configuration

Configuration is immutable after you pass it to Amplitude.

Description

The purpose of these changes is because having both configuration and isBuilt publicly mutable is misleading, since changing those attributes will have no impact.

For example, currently it is possible to initialize Amplitude

final amplitude = Amplitude(Configuration(apiKey: "xxx"));

And then write

amplitude.configuration.flushQueueSize = 1;

Thinking this would lead to a on-the-fly reconfiguration of amplitude, which is not true.

Similarly but less important, I made isBuilt final since previosuly it would be possible to modify it, which makes no sense.

- The purpose of these changes is because having both configuration and isBuilt
publicly mutable is misleading, since changing those attributes will have no impact.
@gabrielgarciagava gabrielgarciagava force-pushed the hide-configuration-from-interface branch from cbf9f97 to aa863e9 Compare March 5, 2025 15:09
@chungdaniel chungdaniel requested a review from Mercy811 March 5, 2025 23:42
@gabrielgarciagava gabrielgarciagava changed the title Hides configuration from public interface and make isBuilt final refactor: Hides configuration from public interface and make isBuilt final Mar 6, 2025
@gabrielgarciagava
Copy link
Contributor Author

This removes a field from the public interface, which means it is a breaking change.
However, using this field is completely useless. If someone is using it, it is probably just a bug.

So my question is if this should create a new major release or not.

@Mercy811
Copy link
Contributor

Mercy811 commented Mar 6, 2025

Hi @gabrielgarciagava, thanks for bringing this up. It makes sense to me that it's kind of misleading. We will make isBuilt final but will keep configuration there to avoid breaking changes.

@gabrielgarciagava
Copy link
Contributor Author

Of course. But please consider hiding it in a next major release. Or at least making the field final, such as all configuration fields as well.

This way a user of the library will never be able to modify the configuration anymore after amplitude is initialized, which makes sense since it is not supported.

@gabrielgarciagava
Copy link
Contributor Author

gabrielgarciagava commented Mar 7, 2025

Just one use case to show you the motivation behind it.

When using version 3 we used to have the following code

final amplitude = Amplitude();
...
amplitude.enableCoppaControl();

When moving to version 4, someone just followed the naive substitution, which was allowed by the library interface

final amplitude = Amplitude(Configuration(apiKey: ...));
...
amplitude.configuration.enableCoppaControl = true;

Which of course is now wrong, but one needs to read the library implementation to realize it.

@@ -29,13 +28,13 @@ class Amplitude {
/// // If care about init complete
/// await amplitude.isBuilt;
/// ```
Amplitude(this.configuration, [MethodChannel? methodChannel]) {
Amplitude(Configuration configuration, [MethodChannel? methodChannel]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed, if you could revert the changes to hiding Configuration for now and leave in making isBuilt final I'd be happy to approve this and get this merged!

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.

3 participants