Skip to content
pubscout

global_assert

1.0.0, released 5 years ago by christophermcasey.com

Perform build-time assertions on constants so misconfigured apps fail at compilation.

WASM-ready
$ flutter pub add global_assert
Source repository

What it does

Provides an @Assert annotation to validate constant values at build time. It ensures that apps with invalid configurations fail to compile rather than failing at runtime.

AI-written summary of version 1.0.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You configure your app using const values and environment variables.
  • You want to catch configuration errors during compilation instead of runtime.

Skip it when

  • You need dynamic runtime configuration validation.

Strengths

  • Fails compilation early for misconfigurations.
  • Requires meaningful error messages for assertions.

Weaknesses

  • Expected to be deprecated when Dart natively supports metaprogramming.

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
0
@Assert(
  myBuildTimeVal == 'val1' || myBuildTimeVal == 'val2',
  'myBuildTimeVal must be one of "val1" or "val2"',
)
const myBuildTimeVal = String.fromEnvironment('MY_VAL');

void main() {
  print('myBuildTimeVal is "$myBuildTimeVal"');
}

Alternatives

Packages that do the same job and could replace global_assert.

  • antlr4

    Dart runtime libraries for ANTLR 4 parser generator.

  • cryptography_flutter

    Flutter plugin that lets the cryptography package use native OS crypto APIs for faster, compliant operations.

  • system_clock

    Dart timekeeping facilities to get system uptime and elapsed time.

  • flutter_olm

    Builds the native Olm library for Android and iOS to be used via dart:ffi.