Flutter의 SharedPreferences를 래핑한 가볍고 사용하기 쉬운 래퍼로, Flutter 애플리케이션에서 지속적인 데이터 저장을 간소화하도록 설계되었습니다. 저장, 검색, 키-값 쌍 삭제와 같은 일반적인 작업을 최소한의 반복 코드로 추상화합니다. 완전한 데이터베이스의 복잡성 없이 기본적인 로컬 스토리지만 필요로 하는 소규모 앱에 적합합니다. 이 패키지는 크로스플랫폼으로 Android, iOS, Web, macOS, Windows, Linux를 지원하여 다양한 배포 시나리오에 유용합니다.
사용 사례
사용자 선호 사항 저장
세션 간에 앱 상태 저장
작은 양의 데이터 캐싱
간단한 설정 관리
로그인 토큰 유지
사용자 활동 추적
주요 기능
최소 API 표면
자동 유형 직렬화
크로스 플랫폼 호환성
간단한 설정
경량 피트프린트
오류 처리
적합한 대상
초보자 플러터 개발자
작은에서 중간 규모의 앱
프로토타입 및 MVP
기본적인 지속성 요구 사항을 가진 앱
복잡한 데이터베이스 설정을 피하는 프로젝트
고려 사항
대규모 데이터 세트에 적합하지 않습니다
쿼리 또는 인덱싱에 대한 지원 없음
키-값 저장에 제한됨
기본적으로 데이터가 암호화되지 않음
고주파 쓰기 시 성능 저하 발생
비중요하고 소규모 데이터에 가장 적합
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
Simple Database
A simple lightweight wrapper for the SharedPreferences Flutter package. Simple Database provides an abstraction layer for storing objects instead of key, value pairs. This makes it very easy to get a quick local storage solution up and running.
Please add simple_database as a dependency in your pubspec.yaml file
No Setup Primative Storage
You can easily setup a database of primitive types just by assigning it a name, Simple Database will init the DB if it has not been created yet on the phone for you.
You can use a single database that stores multiple primitive types and then specify what type you want from the database.
voidmain() async {
SimpleDatabase names = SimpleDatabase(name: 'names');
await names.add('Bob');
await names.add(150)
await names.add('Doug');
//Print out all strings in the dbfor (var name inawait names.getAllType<String>()) {
print(name);
}
//Print out at an index, with a typevar number = await names.getAtType<int>(1);
print(number);
}
Non-Primitive object storage
You can store your own objects you have created easily just by implementing 2 functions in the class. toJson and fromJson. You will need to pass the fromJson function to the constructor of SimpleDatabase if you want it to rebuild the json into your object. You do not need this, it will just return a hash map with the values from your object if the function is not provided.