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

Energizr -- Energy for The Visionary Software Solutions Measurement & me_sure_meant API

example/energizr_example.dart

import 'package:energizr/energizr.dart';

void main() {
  energyDemo();
}

void energyDemo() {
  final calories = 250.kiloCalories();
  var added = calories + 25.kiloCalories();

  /// + supported
  assert(added.magnitude.toNum() == 275);
  assert(added.unit == Calorie.kilocalorie);

  /// Objects are immutable: calculations yield new objects.
  assert(calories.magnitude.toNum() == 250);
  assert(calories.unit == Calorie.kilocalorie);

  /// - supported
  var subtracted = calories - 100.kiloCalories();
  assert(subtracted.magnitude.toNum() == 150);
  assert(subtracted.unit == Calorie.kilocalorie);

  /// Unit conversion between units of same type (e.g. [Energy])
  var asKJ = calories.toUnit(Joule.kilojoule);
  assert(asKJ.magnitude.toNum() == 1046);
  assert(asKJ.unit == Joule.kilojoule);

  /// Common base type enables math between mixed units with auto-conversion
  var mixedMath = asKJ + calories;
  assert(mixedMath.magnitude.toNum() == 2092);
  assert(mixedMath.unit == Joule.kilojoule);

  /// Conversion yields equivalent result when converted back
  var backToCal = mixedMath.toUnit(Calorie.kilocalorie);
  assert(backToCal.magnitude.toNum() == 500);
  assert(backToCal.unit == Calorie.kilocalorie);
}
1
likes
150
pub points
0%
popularity

Publisher

verified publishervisionary.software

Energizr -- Energy for The Visionary Software Solutions Measurement & me_sure_meant API

Repository

Documentation

API reference

License

GPL-3.0 (license)

Dependencies

me_sure_meant

More

Packages that depend on energizr