Flutter shared preferences customized plugin. Secure, Encrypted, Simplified use, Simple key-value pairs storage.
In your flutter project add the dependency:
dependencies:
...
glutton: ^2.0.0
import 'package:glutton/glutton.dart';
bool isSuccess = await Glutton.eat(key, data);
dynamic data = await Glutton.vomit(key);
bool isExist = await Glutton.have(key);
bool isSuccess = await Glutton.digest(key);
await Glutton.flush();
The current answer is no.
Written in JSON and Serialization, flutter doesn't provide library like GSON or Moshi. Such a library would require using runtime reflection, which is disabled in Flutter. So we can't automatically turn class into json or the opposite, but we need to transform it manual first to edible data type.
Save:
/// 1. Create user object
User user = User(
name: "Gentleton",
age: 21,
createdAt: DateTime.now(),
);
/// 2. Transform user object to map
Map<String, dynamic> userMap = user.toJson();
/// 3. Save user map inside glutton
bool isSuccess = await Glutton.eat(<UserKey>, userMap);
Retrieve
/// 1. Retrieve user map inside glutton
Map<String, dynamic>? userMap = await Glutton.vomit(<UserKey>);
/// 2. Transform user map to user object
User user = User.fromJson(userMap);
Save:
/// 1. Set selected date
DateTime date = await showDatePicker(
context: context,
initialDate: _selectedDate,
firstDate: DateTime(1990),
lastDate: DateTime(2030),
);
/// 2. Save selected date inside glutton
await Glutton.eat(<DateKey>, date);
Retrieve
/// 1. Retrieve user map inside glutton
DateTime? date = await Glutton.vomit(<DateKey>);
Save:
/// 1. Retrieve index of enum
int index = Season.index;
/// 2. Save index inside glutton
await Glutton.eat(<enumKey>, index);
Retrieve
/// 1. Retrieve index inside glutton
int? index = await Glutton.vomit(<enumKey>);
/// 2. Transform index to enum
Season _season = SeasonManager.fromIndex(index);
You can follow Season enum for step 2 retrieve enum