settings_yaml 3.4.1 copy "settings_yaml: ^3.4.1" to clipboard
settings_yaml: ^3.4.1 copied to clipboard

outdated

Provides a simple means of saving/loading settings from a yaml file without the yaml fuss.

example/example.dart

import 'package:settings_yaml/settings_yaml.dart';

void main() {
  save();

  load();
}

void save() {
  final settings = SettingsYaml.load(pathToSettings: '.settings.yaml');

  settings['dbname'] = 'billing';
  settings['dbusername'] = 'username';
  settings['dbpassword'] = 'apassword';
  settings['timeout'] = 300;
  settings['coefficient'] = 10.85;
  settings['active'] = true;

  settings.save();
}

void load() {
  final settings = SettingsYaml.load(pathToSettings: '.settings.yaml');

  assert(settings.validString('dbname'), 'Should be a string');
  assert(settings.validInt('timeout'), 'Should be an int');
  assert(settings.validDouble('coefficient'), 'Should be a double');
  assert(settings.validBool('active'), 'Should be a bool');

  final dbname = settings['dbname'] as String;
  // we haven't validated the dbusername and dbpassword so
  // they could be null.
  final username = settings['dbusername'] as String?;
  final password = settings['dbpassword'] as String?;

  final timeout = settings['timeout'] as int;
  final coefficient = settings['coefficient'] as double;
  final active = settings['active'] as bool;

  print('dbname $dbname, username: $username, password: $password, '
      'timeout: $timeout, coefficient: $coefficient, active: $active');

  settings.save();
}
15
likes
0
pub points
81%
popularity

Publisher

verified publisheronepub.dev

Provides a simple means of saving/loading settings from a yaml file without the yaml fuss.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

collection, dcli_core, meta, path, uuid, yaml

More

Packages that depend on settings_yaml