Skip to content
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

[critical] 2.3.0 Breaks release build at runtime #29

Closed
kj415j45 opened this issue Jul 20, 2023 · 2 comments · Fixed by #30
Closed

[critical] 2.3.0 Breaks release build at runtime #29

kj415j45 opened this issue Jul 20, 2023 · 2 comments · Fixed by #30
Labels
bug Something isn't working

Comments

@kj415j45
Copy link
Contributor

2.3.0 Introduce changes in #7 , which provides ability for app for Windows to react with system accent color changes.

It should be an awesome updates, but, a mistake was made there. As per #28 mentioned, while trying to stream the accent color, cause LateInitializationError.

Beyond that, it actually break release build of other platform (At least Web and Android are breaking). For debug build, it works fine with console error, but all things works. However, in a release build,
this error can break the whole initialization phase and result a blank app without anything. It also makes web build hang up and finally being marked as no respond.

If I understand correctly:

static final SystemAccentColor accentColor = SystemAccentColor(fallbackColor)
..load();

Here, try to initialize final variable SystemTheme.accentColor with SystemAccentColor(fallbackColor)..load(). During the load(),
/// Updates the fetched accent colors on Windows.
Future<void> load() async {
WidgetsFlutterBinding.ensureInitialized();
_subscription = SystemTheme.onChange.listen((color) {
accent = color.accent;
light = color.light;
lighter = color.lighter;
lightest = color.lightest;
dark = color.dark;
darker = color.darker;
darkest = color.darkest;
});

SystemTheme.onChange getter was called, and it return Stream.value(accentColor) on platform other than Windows.
static Stream<SystemAccentColor> get onChange {
if (kIsWeb || !Platform.isWindows) return Stream.value(accentColor);
return _eventChannel.receiveBroadcastStream().map((event) {
return SystemAccentColor._fromMap(event);
}).distinct();
}

The variable accentColor should be evaluate immediately, and it actually means SystemTheme.accentColor, which is still initializing. Then cause LateInitializationError.

Here's my current investigation report. I'm not sure why it will make web build no respond as it should be failed or crash at start time, there may be other deeper issue.

@longfit
Copy link

longfit commented Jul 20, 2023

I have tested system_theme example at flutter 3.10.6
on platform
1 .Chrome fail ( show Error: LateInitializationError: accentColor) but shown unexpected result
2. windows Success
3. Android fail show Error: LateInitializationError: accentColor)
4. Linux fail ( pause on exception)

@bdlukaa bdlukaa added the bug Something isn't working label Jul 20, 2023
@bdlukaa
Copy link
Owner

bdlukaa commented Jul 20, 2023

The solution may be just subscribe to the onChange stream after resolving the colors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants