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

GitHub 저장소xaldarof/jt-preferences

jt_preferences

Preferences 는 프로젝트에 원활하게 통합되어 사용자 경험과 앱 기능을 향상시킵니다. JT Preferences 를 통해 설정 관리를 간소화하고 앱을 최적화하세요.

jt_preferences 프로젝트 이미지
스타
5
포크
0
최근 푸시(UTC)
2025. 2. 21.
프로젝트 상태
보관됨

원본 README

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

JtPreferences

pub package

Supported data types are int, double, bool, String and Writable object.

Usage

To use this plugin, add jt_preferences as a dependency in your pubspec.yaml file .

Examples

Here are small examples that show you how to use the package.

Initialize
void main(List<String> args) async {
  //for example (data/data/com.example.application/) without absolute path
  await JtPreferences.initialize("path/path", encryptionKey: '16 length encryption key');
  //Data will be encrypted if encryptionKey is not null
}
Write data
// Obtain shared preferences.
final preferences = await JtPreferences.getInstance();

// Save an integer value to 'counter' key.
await preferences.setInt('counter', 10);
// Save an boolean value to 'repeat' key.
await preferences.setBool('repeat', true);
// Save an double value to 'decimal' key.
await preferences.setDouble('decimal', 1.5);
// Save an String value to 'action' key.
await preferences.setString('action', 'Start');

//Save writable object
await preferences.saveObject(User(name: 'user', age: 12));

Example User Writable object
class User extends Writable {
  final String name;
  final int age;

  @override
  factory User.fromJson(Map<String, dynamic> map) {
    return User(name: map['name'], age: map['age']);
  }

  @override
  OnConflictStrategy? get onConflictStrategy => OnConflictStrategy.update;

  @override
  Map<String, dynamic> toJson() {
    return {
      "name": name,
      "age": age,
    };
  }

  User({
    required this.name,
    required this.age,
  });

  @override
  String key => name;
}

Read data
// Try reading data from the 'counter' key. If it doesn't exist, returns null.
final int? counter = preferences.getInt('counter');
// Try reading data from the 'repeat' key. If it doesn't exist, returns null.
final bool? repeat = preferences.getBool('repeat');
// Try reading data from the 'decimal' key. If it doesn't exist, returns null.
final double? decimal = preferences.getDouble('decimal');
// Try reading data from the 'action' key. If it doesn't exist, returns null.
final String? action = preferences.getString('action');

final List<String>? keys = preferences.getKeys();

final object = preferences.getObject('user', (map) => User.fromJson(map));
print(object?.name);
print(object?.age);

//Reload data from storage
_preferences.reload();

Listen changes
//listen all changes
preferences.listen().listen((event) {
  print("key $event updated");
});

//listen only specific key
preferences.stream(key: 'counter').listen((event) {
   print("key $event updated");
});

Remove an entry
// Remove data for the 'counter' key.
final success = await preferences.remove('counter');
xaldarof GitHub avatar
GitHub 작성자

xaldarof ↗

bedroom
언어DartC++CMakeHTMLSwiftCKotlinObjective-C

분류

사용 중인 의존성

의존성 목록 4 개

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

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

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

출처 및 관리

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

GitHub Docs — About repositories ↗