double_extension 1.0.0  double_extension: ^1.0.0 copied to clipboard
double_extension: ^1.0.0 copied to clipboard
A starting point for Dart libraries or applications.
example/double_extension_example.dart
import 'package:double_extension/double_extension.dart';
import 'package:object_extension/object_extension.dart';
void main() {
  final map = {
    'nullValue': null,
    'notNullValue': 3.14,
    'notAllowableValue': 5
  };
  print('Map: ${map.toStructuredString()}');
  print('\nFrom null value in Map (used default value):');
  print(DoubleExtension.fromDynamicE(map['nullValue'], defaultValue: 1.1));
  print('\nFrom expected value in Map  (used default value):');
  print(DoubleExtension.fromDynamicE(map['expectedValue'], defaultValue: 2.2));
  print('\nFrom not null value in Map  (default value not used):');
  print(DoubleExtension.fromDynamicE(map['notNullValue'], defaultValue: 3.3));
  print('\nFrom not allowable value in Map  (default value not used)');
  print('In this case, the "NotAllowableValueException" will be thrown');
  try {
    final value = DoubleExtension.fromDynamicE(map['notAllowableValue'],
        defaultValue: 1.0, allowableValues: { 1.0, 2.0, 3.0});
  } catch(e) {
    print(e);
  }
  print('\nThe same, but with the addition of the "name" parameter');
  print('Now the text of the exception is more informative');
  try {
    final value = DoubleExtension.fromDynamicE(
        map['notAllowableValue'], name: 'notAllowableValue',
        defaultValue: 1.0, allowableValues: { 1.0, 2.0, 3.0});
  } catch(e) {
    print(e);
  }
  print('\nYou can disable the null value using the parameter "nullAllowed"');
}