global_assert 1.0.0 copy "global_assert: ^1.0.0" to clipboard
global_assert: ^1.0.0 copied to clipboard

A micro-library that makes it easy to do build-time assertions about constants so that misconfigured apps fail at build-time instead of failing at runtime.

example/global_assert_example.dart

import 'package:global_assert/global_assert.dart';

@Assert(
  buildTimeString == 'val_1' || buildTimeString == 'val_2',
  'buildTimeString must be one of "val_1" or "val_2".',
)
const buildTimeString = String.fromEnvironment(
  'BUILD_TIME_STRING',
  defaultValue: 'val_1',
);

/// Try running this with:
///
/// ```dart
/// // prints 'val_1'
/// dart global_assert_example.dart
/// ```
///
/// ```dart
/// // prints 'val_2'
/// dart --define=BUILD_TIME_STRING=val_2 global_assert_example.dart
/// ```
///
/// ```dart
/// // compilation error
/// dart --define=BUILD_TIME_STRING=foo global_assert_example.dart
/// ```
void main() {
  print(buildTimeString);
}
4
likes
140
pub points
87%
popularity

Publisher

verified publisherchristophermcasey.com

A micro-library that makes it easy to do build-time assertions about constants so that misconfigured apps fail at build-time instead of failing at runtime.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

More

Packages that depend on global_assert