measurements 0.0.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 48

measurements #

A package providing basic classes for working with measurements such as Length and Mass. All provided classes provide the means to perform conversions, calculations and comparisons using objects.

Available Measurements #

The available classes as well as those that will hopefully be implemented soon are listed below.

  • [x] Length
  • [x] Mass
  • [x] Area
  • [ ] DataTransferRate
  • [ ] DigitalStorage
  • [ ] Energy
  • [ ] Frequency
  • [ ] Pressure
  • [ ] Speed
  • [ ] Temperature
  • [ ] Volume

Example #

Conversions:

import 'package:measurements/measurements.dart';

void main(List<String> arguments) async {
  Length heightOfEverest = Length.fromMetres(8848.0);
  print("Height of Everest (in metres): ${heightOfEverest.inMetres}.");
  print("Height of Everest (in kilometres): ${heightOfEverest.inKilometres}.");
  print("Height of Everest (in yards): ${heightOfEverest.inYards}.");
  print("Height of Everest (in miles): ${heightOfEverest.inMiles}.");
}

Calculations:

import 'package:measurements/measurements.dart';

void main(List<String> arguments) async {
  Area a = Area.fromAcres(87.0);
  Area b = Area.fromAcres(43.0);
  print("a + b is ${(a + b).inAcres} centimetres");
  print("a - b is ${(a - b).inAcres} centimetres.");
  print("a * 4 is ${(a * 4).inAcres} centimetres.");
  print("a / 4 is ${(a / 4).inAcres} centimetres.");
}

Comparisons:

import 'package:measurements/measurements.dart';

void main(List<String> arguments) async {
  Mass elephantWeight = Mass.fromKilograms(5400);
  Mass zebraWeight = Mass.fromKilograms(380);
  if (elephantWeight == zebraWeight) {
    print("An elephant and a Zebra have the same weight.");
  } else if (zebraWeight < elephantWeight) {
    Mass difference = elephantWeight - zebraWeight;
    print("An elephant is ${difference.inPounds} pounds heavier than a zebra.");
  } else {
    Mass difference = zebraWeight - elephantWeight;
    print("A Zebra is ${difference.inPounds} pounds heavier than an elephant.");
  }
}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

0.0.3 #

  • Added support for Area measurements

0.0.2 #

  • Corrected ounces for Mass class
  • Fixed overloaded == operator

0.0.1 #

  • Initial Release

example/main.dart

import 'package:measurements/measurements.dart';

void main(List<String> arguments) async {
  print("Some interesting measurements...");

  // Conversions
  Length heightOfEverest = Length.fromMetres(8848.0);
  print("Height of Everest (in metres): ${heightOfEverest.inMetres}.");
  print("Height of Everest (in kilometres): ${heightOfEverest.inKilometres}.");
  print("Height of Everest (in yards): ${heightOfEverest.inYards}.");
  print("Height of Everest (in miles): ${heightOfEverest.inMiles}.");

  // Calculations
  Area a = Area.fromAcres(87.0);
  Area b = Area.fromAcres(43.0);
  print("a + b is ${(a + b).inAcres} centimetres");
  print("a - b is ${(a - b).inAcres} centimetres.");
  print("a * 4 is ${(a * 4).inAcres} centimetres.");
  print("a / 4 is ${(a / 4).inAcres} centimetres.");

  // Comparisons
  Mass elephantWeight = Mass.fromKilograms(5400);
  Mass zebraWeight = Mass.fromKilograms(380);
  if (elephantWeight == zebraWeight) {
    print("An elephant and a Zebra have the same weight.");
  } else if (zebraWeight < elephantWeight) {
    Mass difference = elephantWeight - zebraWeight;
    print("An elephant is ${difference.inPounds} pounds heavier than a zebra.");
  } else {
    Mass difference = zebraWeight - elephantWeight;
    print("A Zebra is ${difference.inPounds} pounds heavier than an elephant.");
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  measurements: ^0.0.3

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:measurements/measurements.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
48
Learn more about scoring.

We analyzed this package on Mar 31, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Health suggestions

Format lib/measurements.dart.

Run dartfmt to format lib/measurements.dart.

Format lib/src/area.dart.

Run dartfmt to format lib/src/area.dart.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
Dev dependencies
test ^1.11.0