Skip to content

Build failures on Flutter 3.44.4 / Proposal to update hooks and add a guard clause #16

Description

@KomTak001

Hi there, thank you for maintaining this excellent package!
I recently encountered build issues when using the latest version of Flutter. I would like to report the problem and propose a fix.

Environment

  • velopack_flutter: 0.3.2
  • Flutter: 3.44.4 / Dart: 3.12.x
  • Platform: macOS (likely reproducible on Windows/Linux as well)

Problem

Running flutter run or flutter build on Flutter 3.44.4 causes a crash in the native assets build hook (hook/build.dart). This problem occurs in two stages, stemming from dependency versions and hook execution state.

1. Null check error during JSON parsing

Currently, velopack_flutter 0.3.2 depends on hooks ^1.0.3, which in turn resolves code_assets to 1.0.0. This version is incompatible with the newer native assets JSON format emitted by Flutter 3.44.4, resulting in the following error:

Unhandled exception:
Null check operator used on a null value
#0      new CodeConfig._fromJson (package:code_assets/src/code_assets/config.dart:52:67)
#1      HookConfigCodeConfig.code (package:code_assets/src/code_assets/config.dart:21:37)
#2      main.<anonymous closure> (velopack_flutter-0.3.2/hook/build.dart:7:35)

2. Bad state error when overriding to hooks ^2.0.0

To work around the first issue, I used dependency_overrides in my app's pubspec.yaml to force hooks: ^2.0.2. While this makes full builds (flutter build) succeed, incremental builds triggered by flutter run fail with a new error:

Bad state: HookConfig.code should only be accessed when building code assets.
Check HookConfig.buildCodeAssets before accessing HookConfig.code.

This happens because hook/build.dart unconditionally calls input.config.code.targetOS. With the newer hooks package, accessing this property throws an error if buildCodeAssets == false (which is the case for incremental builds).

Suggested Fix

To fully resolve this issue and eliminate the need for developers to use app-level dependency_overrides, would it be possible to apply the following two changes in a future release?

1. Update dependencies
Update the package dependencies to use hooks: ^2.0.0 (and consequently code_assets: ^1.2.0).

**2. Add a guard clause in hook/build.dart**
Add a check at the top of the file (before accessing input.config.code) to return early if code assets are not being built:

if (!input.config.buildCodeAssets) return;

I have verified locally that applying this dependency update along with the guard clause successfully allows both flutter build macos --debug and flutter run to complete without any errors.

Thank you for your time and assistance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions