패키지, 저장소 및 앱 카테고리 검색

GitHub 저장소onepub-dev/settings_yaml

settings_yaml

onepub-dev/settings_yaml open-source repository details.

settings_yaml 프로젝트 이미지
스타
4
포크
4
최근 푸시(UTC)
2025. 8. 9.
프로젝트 상태
활성

원본 README

아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.

Provide a very simple method to use yaml files for reading/writing an app's configuration.

Saving a config data

void save() {
  /// create a new .settings.yaml
  var settings = SettingsYaml.load(pathToSettings: '.settings.yaml');

  settings['dbname'] = 'billing';
  settings['dbusername'] = 'username';
  settings['dbpassword'] = 'apassword';
  settings['timeout'] = 200;
  settings['ats'] = <String>['cat', 'bat', 'rat'];
  settings['hosts'] = <String, String>{
        'host1': 'one',
        'host2': 'two',
        'host3': 'three'
      };

  settings.save();
}

Loading config data

void load() {

  /// load an existing .settings.yaml, if it doesn't exist then create it.
  var settings = SettingsYaml.load(pathToSettings: '.settings.yaml', create: true);

  /// Access simple top level keys.
  var dbname = settings['dbname'] as String;
  var username = settings['dbusername']as String;
  var password = settings['dbpassword']as String;
  var timeout = settings['timeout']as String;
  var ats = settings['ats']; // List<dynamic>


  
  List<String> atsAsString = settings.asStringList['ats'];
  var hosts = settings['hosts'] as Map<String, String>;

  settings['a_String'] = 'hello world';
  settings['an_int'] = 10;
  settings['a_double'] = 10.0;
  settings['a_bool'] = true;

  var a_String = settings.asString('a_String');
  var an_int = settings.asInt('an_int');
  var a_double = settings.asDoule('a_double');
  var a_bool = settings.asBool('a_bool');


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

  /// change something
  var newPassword = ask('password');
  settings['dbpassword'] = newPassword;

  /// Write a map into a top level key.
  settings['hosts'] = <String, String>{
        'host1': 'one',
        'host2': 'two',
        'host3': 'three';
  settings['ats'] = <String>['cat', 'bat', 'rat'];

  
  settings.save();

}

Access nested content

SettingsYaml also provides access to nested attributes using path selectors with the selectAsXXXX group of methods:

 var content = '''name: brett
hostname: slayer
port: 10
active: true
volume: 10.0
imageid: "65385002e970"
people:
  - person:
    name: brett
  - person:
    name: john
''';

    var settings = SettingsYaml.fromString(content: content, filePath: path);
    // use a path selector to read an attribute.
    expect(settings.selectAsString('people.person[0].name'), equals('brett'));
    expect(settings.selectAsString('people.person[1].name'), equals('john'));

Each selector is made up of a word.

To access an element in a list use 'word[n]'. where 'n' is the nth instance of the word in a yaml array.

e.g.

one:
  - two
  - two
    three:
      name: brett
      password: abc123

To return the value of four

settings.selectAsString('one.two[1].three.name') == 'brett'
settings.selectAsString('one.two[1].three.password') == 'abc123'

You can also get a Dart map or list:

settings.selectAsString('one.two[1].three') as Map;
settings.selectAsString('one')  as List;
OnePub GitHub avatar
GitHub 작성자

OnePub ↗

언어Dart

사용 중인 의존성

의존성 목록 7 개

프로젝트에 맞는 저장소를 선택하려면?

사용 목적에 따라 검색하고 개발 활동을 비교한 뒤 원본 저장소에서 요구 사항을 확인하세요.

  1. 이름, 작성자 또는 설명으로 검색하고 기술 주제로 범위를 좁힙니다.
  2. 스타, 포크, 최근 푸시를 함께 비교하세요. 스타는 관심의 지표이며 품질을 보장하지 않습니다.
  3. 사용하기 전에 GitHub에서 README, 라이선스, Issues를 확인하세요.

출처 및 관리

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗